Error message in code
I've been trying to make a program that splits a sentence into words and I keep getting this error message which I'm not sure how to fix.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> words;
string getSent ();
void splitSent (string sent);
int main ()
{
string sent;
cout << "Enter your sentence: " << endl;
getline (cin, sent);
splitSent (sent);
return 0;
}
string getSent ()
{
string sent;
cout << "Enter your sentence: " << endl;
getline (cin, sent);
return (sent);
}
void splitSent (string sent)
{
int Pos = 0; // Position
string word;
while (Pos < sent.length())
{
while (Pos < sent.length() && (sent.length() != ' '))
{
word += sent[Pos];
Pos++;
};
words.push_back(word)
cout << word << endl;
Pos++;
}
}
|
The error is "[Error] expected unqualified-id before '.' token" at line 42.
typedef
creates an alias for a type.
By instance you may do
1 2
|
typedef int number;
number foo;
|
So `words' is a type, like `int'. It is not an object.
go to line 42 and see if you have a ;
Topic archived. No new replies allowed.