Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[HELP][SOLUTION!] C++ File I/O

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Sun Jun 15, 2008 3:27 pm    Post subject: [HELP][SOLUTION!] C++ File I/O Reply with quote

I am a fairly good C++ programmer, but I am a little rusty becuase I took a break. I have done file I/O before, but nothing special... I have recently been trying to make a program that will read the lines of a program then stop when there is a blank line.

Any ideas? I have made the code, compiles fine, then try it but it goes on forever putting blank lines into the command promt window. I made my program see if there was a blank line by useing getline(var), then checking if it has a value, then breaking.

Help!

EDIT:

-SOLUTION-

Code:
while(!file_io.eof()){
    file_io.getline(var);
    cout << var << endl;
    }


I used the eof() function, which checks for End Of File oppened. The while statment continues to record the lines until the End Of File is reached.

This is a new statement I found by accident on a website, although i did find it in one of my C++ books later...


Last edited by Chaosis13 on Sun Jun 15, 2008 3:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sun Jun 15, 2008 3:55 pm    Post subject: Reply with quote

Could you be a bit more specific? Why does it keep on putting blank lines?

To answer your question, use this code:

Code:
if (var == "") {
//Do whatever if it is blank line
}
else {
//Do whatever if it is not a blank line
}


Please be a bit more specific, as it is not too clear as to what you are trying to accomplish.

And what do you mean by "Reading the lines of a program"?
Back to top
View user's profile Send private message Send e-mail
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Sun Jun 15, 2008 4:00 pm    Post subject: Reply with quote

Sorry if I wasn't specific, I was making a program that reads the lines of a file(program), and I had something like your code along with a while statement, but the code wouldn't break for some reason.... I still do not know what happend.

Thank you anyway. (I found solution, above).
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sun Jun 15, 2008 4:03 pm    Post subject: Reply with quote

You could also use

Code:
if (myfile.good())....


But im glad u solved your problem!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites