• 13
• 17
• 27
• 9
• 9

# Urgent! ifstream string won't work!

This topic is 4808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

input >> strFile;


have all the right headers won't work! why?

##### Share on other sites
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]

##### Share on other sites
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]

##### Share on other sites
Quote:
 Original post by Sagar_Indurkhyawon't work! why?

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

##### Share on other sites
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!

##### Share on other sites
Quote:
 Original post by Sagar_Indurkhyafixed it. Another question however.suppose i am working with C, and havelong long a = 0;how could i use scanf("...", &a);???thanks for all the help so far though!

long long a = 0;
scanf("%ll", &a);

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by mumpoI 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

##### Share on other sites
Quote:
 Original post by mumpoI 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.