ifstream >> string???

P

persres

Hi,
The following code doesnt compile.

int main()
{
ifstream ftext;
string word;
vector <string> vs;
ftext.open("data.txt");
if (!ftext)
exit (-1);
while (ftext>>word) // as long as sizeof hasn't been reached
{
vs.push_back(word); //copy word to vector
}
}

(Taken from - http://www.devx.com/tips/Tip/14354).

The main problem is ftext>>word. Why cant I read an ifstream into a
string?.

I have visual studio 2008. Is there any reason why such an overload is
not provided?
Or am I doing something wrong?
Thanks
 
P

persres

(e-mail address removed):








Yes, you failed to provide the complete program (esp. include statements)
as well as the actual error message. However, my crystal ball tells me
you are missing an #include <string> line. Hint: read the manual to find
out which header must be included for the operator you are using.

Oh. I am sorry. I am coming to C++ after a few years and I just
screwed up. That was silly.
Thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top