How do i get the contents of a file into a buffer so that i can use some <string> functions on it?
Cheers
How do i get the contents of a file into a buffer so that i can use some <string> functions on it?
Cheers
Last edited by wart101; 12-11-2006 at 01:54 AM.
WhAtHA hell Is GoInG ON
Dunno if this is what you wanted:
http://www.arachnoid.com/cpptutor/student2.html
Sorry i wasn't to clear, i know how to ge a file into a buffer but i want to convert it from (const * char) to (string) but i don't know how to.Originally Posted by g4j31a5
I hope that makes sence.
WhAtHA hell Is GoInG ON
I think the fstream's getline() function can have a string as the output parameter (CMIIW). Or why don't you use the copy constructor of the string? E.g.
Code:char str1[]="Hello World!"; std::string str2=str1;
If you want to read the entire contents of a file into a string object you can use a stringstream as an intermediate object.
Code:ifstream file("foo.txt"); stringstream sstr; string info; if( file.is_open() ) { sstr << file.rdbuf(); // Read entire file into stringstream info = sstr.str(); // Convert stringstream into string // Do whatever you want with the string "info". }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Thanks mate that is exactly what i needed, cheers.Originally Posted by hk_mp5kpdw
WhAtHA hell Is GoInG ON