Urgent! ifstream string won't work!

Started by
8 comments, last by mumpo 19 years, 3 months ago
I have this:

string strFile;
ifstream input("theFile.txt", std::ios_base::in);

input >> strFile;

have all the right headers won't work! why?
Advertisement
EDIT: Sorry if I was spreading misinformation. I tried to find evidence in MSDN that the >> operator is defined for string objects, but failed. Since I had never used it before myself, either, I assumed that it did not exist.

[Edited by - mumpo on January 17, 2005 10:24:16 PM]
Ignore the previous

std::string does work with input stream >> operators.
What problems exactly are you having? List the compile errors

btw: How on earth did you get such a low rating ? 00

[Edited by - ProPuke on January 17, 2005 12:31:25 PM]
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
Quote:Original post by Sagar_Indurkhya
won't work! why?


Because you made an error.

Tell me in what ways it "won't work", and I'll tell you why.
fixed it. Another question however.

suppose i am working with C, and have

long long a = 0;

how could i use scanf("...", &a);

???

thanks for all the help so far though!
Quote:Original post by Sagar_Indurkhya
fixed it. Another question however.

suppose i am working with C, and have

long long a = 0;

how could i use scanf("...", &a);

???

thanks for all the help so far though!


long long a = 0;
scanf("%ll", &a);
I edited out my earlier apply, since it was apparently incorrect. However, MSDN doesn't list istream::operator>>(string&) or anything like that that I could find. Can someone post me a link proving that it is part of the STL? Obviously one could easily just make an operator like that, but I want to see the evidence that it is supposed to be predefined.
Quote:Original post by mumpo
I edited out my earlier apply, since it was apparently incorrect. However, MSDN doesn't list istream::operator>>(string&) or anything like that that I could find. Can someone post me a link proving that it is part of the STL? Obviously one could easily just make an operator like that, but I want to see the evidence that it is supposed to be predefined.


That's because its part of the string class itself. Here is the link for that operator and this one for all of them.

- Drew
Quote:Original post by mumpo
I edited out my earlier apply, since it was apparently incorrect. However, MSDN doesn't list istream::operator>>(string&) or anything like that that I could find.
It's not a member:
istream & operator >> (istream & is, std::string & s);

Quote:Can someone post me a link proving that it is part of the STL?
It's not part of the STL, either. STL is the name for a proprietary library developed by HP and SGI which was largely adopted as the basis for the Standard C++ Library. In many respects, you could consider the Standard C++ Library to be the sum of the Standard Template Library and IOstreams, plus the Standard C Library.

It took some digging, but I found this documentation for you.
@Drew_Benton and Oluseyi: Thank you for the links. That is strange that the operator is defined externally though. I would guess that they did it that way in order to not give it access to private members, since it doesn't need it to get the job done, and to avoid requiring that a project use string if it is going to use istream.

This topic is closed to new replies.

Advertisement