This is my problem:
I want the user to input a sentence or line of both integers and characters, read in the whole line,spaces and all, then parse through the line, if it is an integer push it into an vector of integers, if it is a character, push it into a vector of characters.
This is what I have so far, but it errors out on the "while(getline(line, s)" line of code
vector<int> operands;
vector<char> actionOperator;
cout << "Please enter an arithmetic equation: " ;
char str[50];
string line;
string s;
char c;
cin.getline(str, 50);
line = str;
cout << str << endl;
while(getline(line, s))
{
if(s.empty())
break;
// make an istream object
istringstream iss(s);
int i = 0;
if(iss >> i)
operands.push_back(i);
else if (iss >> c)
actionOperator.push_back[c]
}
I want the user to input a sentence or line of both integers and characters, read in the whole line,spaces and all, then parse through the line, if it is an integer push it into an vector of integers, if it is a character, push it into a vector of characters.
This is what I have so far, but it errors out on the "while(getline(line, s)" line of code
vector<int> operands;
vector<char> actionOperator;
cout << "Please enter an arithmetic equation: " ;
char str[50];
string line;
string s;
char c;
cin.getline(str, 50);
line = str;
cout << str << endl;
while(getline(line, s))
{
if(s.empty())
break;
// make an istream object
istringstream iss(s);
int i = 0;
if(iss >> i)
operands.push_back(i);
else if (iss >> c)
actionOperator.push_back[c]
}