Skip to main content
gamedev.net
🔒 Locked

Strings

Started by HIPOPO 3 replies 400+ views
Original Post
HIPOPO
HIPOPO
Hello I am using C/C++ DirectX 8.0. I was making a program that saves a directory string to a .txt file and when I loaded the string it only loaded everything up to the space. Can someone please tell me a way to get the whole string from the file? I was thinking of letting the user enter in the number of spaces the string has and then loading each peice of the string from the file, but there has to be a better way then that. Thanks. here is the code I am loading the string with: void loadbuttonsdirectory() { ifstream in("buttonsdirectory.txt"); if(in) { for(int index=0; index<20; index++) { in >> buttons[index].directory; } in.close(); } } [edited by - HIPOPO on May 21, 2003 8:46:42 PM]
antareus
antareus

  
#include <string>

using namespace std;

string line = "";
ifstream file("
yourfile.txt");
getline(file, line); //gets the whole line up to \n



--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
HIPOPO
HIPOPO
It apears to me that you are headed right for what I am looking for, but I don't understand how to use it... Is line the charcter to get? I tried to get it to work, but had no luck... Could you please explaine a little about how to use the code you gave.
Thanks.


[edited by - HIPOPO on May 21, 2003 10:44:45 PM]
HIPOPO
HIPOPO
Someone please help me!!!! I know someone knows how to do this. look at antareus post that is near what I need. There have been 54 people that have viewed this so far someone has to know. Don''t be shy to speak up .
Thank in advance.
antareus
antareus
quote:
Can someone please tell me a way to get the whole string from the file?

getline gets the string up to a new line character and puts it in line like I said up there. It would work if your file was like this:
c:\program files\my program with spaces in its name\more spaces
more stuff here that isn''t gotten


line would be "c:\program files\my program with spaces in its name\more spaces"
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.