F
Frankie Montenegro
Hi everyone,
I need some help with the following C++ code. It is supposed to read input
line by line, each line as one string; then split each string into its
component words and store these components in a vector<string> (so it
would be a vector of strings per line)
('Split' function mentioned in the code is defined elsewhere and it workes
fine; it splits a line of input into words and stores them in
vector<string>.)
code:
#include <iostream>
#include <string>
#include <vector>
#include "split.h"
//using declarations
struct split_phrase
{
vector<string> words;
};
int main()
{
string s;
vector<string> phrase;
vector<split_phrase> sp;
while (getline(cin,s))
phrase.push_back(s);
for (vector<string>::size_type i=0; i!=phrase.size(); ++i)
ERROR HERE! (sp.words).push_back(split(phrase));
cout<<sp[2].words[3];
return 0;
}
Below is the only error returned. I don't understand why it shows. ANy thougths?
code:
5-1.cc: In function `int main()':
I need some help with the following C++ code. It is supposed to read input
line by line, each line as one string; then split each string into its
component words and store these components in a vector<string> (so it
would be a vector of strings per line)
('Split' function mentioned in the code is defined elsewhere and it workes
fine; it splits a line of input into words and stores them in
vector<string>.)
code:
#include <iostream>
#include <string>
#include <vector>
#include "split.h"
//using declarations
struct split_phrase
{
vector<string> words;
};
int main()
{
string s;
vector<string> phrase;
vector<split_phrase> sp;
while (getline(cin,s))
phrase.push_back(s);
for (vector<string>::size_type i=0; i!=phrase.size(); ++i)
ERROR HERE! (sp.words).push_back(split(phrase));
cout<<sp[2].words[3];
return 0;
}
Below is the only error returned. I don't understand why it shows. ANy thougths?
code:
5-1.cc: In function `int main()':