Where's my C2061?

G

Guest

arrayStr and intString are both failing a C2061 error

// median.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
string arrayStr = "";
string intString = "";

cout << "Enter an array of integers" << endl;

do
cin >> intString;
C2061 arrayStr = arrayStr + intString + " ";
C2061 while intString != "";

cout << arrayStr << endl;

return 0;
}

A better question would be how do I enter a string of numbers separated by
spaces? I need a variable length array of integers.

And, why has Studio.NET stopped "Please press any key to continue" in the
command prompt window?

I haven't done C++ programming in a while and I'm having more trouble than I
ever had when I was first learning.
 
D

David Wilkinson

plains5728 said:
arrayStr and intString are both failing a C2061 error

// median.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
string arrayStr = "";
string intString = "";

cout << "Enter an array of integers" << endl;

do
cin >> intString;
C2061 arrayStr = arrayStr + intString + " ";
C2061 while intString != "";

cout << arrayStr << endl;

return 0;
}

A better question would be how do I enter a string of numbers separated by
spaces? I need a variable length array of integers.

And, why has Studio.NET stopped "Please press any key to continue" in the
command prompt window?

I haven't done C++ programming in a while and I'm having more trouble than I
ever had when I was first learning.

plains:

Your do-while syntax is wrong:

do
{
cin >> intString;
arrayStr = arrayStr + intString + " ";
}
while (intString != "");

You might want to look at std::getline().

"Please press any key to continue" does not appear when you run under
the debugger.

David Wilkinson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top