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 


FI/FO(file input/file output) problem/question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Apr 01, 2008 10:36 pm    Post subject: FI/FO(file input/file output) problem/question Reply with quote

I decided to try to learn file input/file output(FI/FO) and so I was reading about it and made a test program:

Code:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
   char filename[80];
   char buffer[255];
   
   cout<<"File name: ";
   cin>>filename;
   ifstream fin(filename);
   if (fin) {
      cout<<"Current file contents: \n";
      char ch;
      while(fin.get(ch)) {
         cout<<ch;
      }
   }
   fin.close();
   
   cout<<"Opening file...\n";
   ofstream fout(filename, ios::ate);
   if (!fout) {
      cout<<"Could not open "<< filename <<" for writing.\n";
      return(1);
   }
   
   cout<<"Text to be written: \n";
   cin.ignore(1, '\n');
   cin.getline(buffer, 255);
   fout<< buffer << "\n";
   fout.close();
   
   fin.open(filename);
   if (!fin) {
      cout<<"Could not open "<< filename <<" for reading.\n";
      return(1);
   }
   
   cout<<"Contents of file: \n";
   char ch;
   while(fin.get(ch)) {
      cout<<ch;
   }
   fin.close();
   return 0;
}


But when I compile and run this, as soon as I type it what I want to write and click enter, my program shuts down. And my compiler isn't giving me any warnings or errors or anything. I can't really find the problem. Can you guys help?

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Wed Apr 02, 2008 8:18 pm    Post subject: Reply with quote

Most likely because your program executes very fast. If you have MSVS 2k5 go to debug-> start without debugging. Tell me if it still doesn't work. If you don't have MSVS 2k5 add cin or system("pause") at the end.
Back to top
View user's profile Send private message AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Apr 02, 2008 8:27 pm    Post subject: Reply with quote

no system pause, use cin:

cin.sync();
cin.ignore();

before return 0;

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Apr 02, 2008 9:22 pm    Post subject: Reply with quote

I've never had that happen before. I remember before, on short like 8 line programs when I was beginning to learn C++, like hello world and stuff it would happen. But I never experienced with anything that was somewhat lengthy (in terms of a simple program).

edit:

It still isn't working. It will write to the file fine, and save the file, just not, display its contents. Any other reasons why it's closing before it displays the contents?

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Wed Apr 02, 2008 9:40 pm    Post subject: Reply with quote

try
Code:

while(!fin.eof()) {
      cout<<fin.get();
   }

Also, try setting up messageboxes or random couts to see where your program is and isn't executing.
Back to top
View user's profile Send private message
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