i/o with .txt files.......
Hello again. I had a question about input and output on .txt files. Could you show me some code (VC++) demonstrating how to read and output in an .exe from a .txt file. And also, how to write to a .txt from an .exe. Both reading and writing to and from a .txt file I should say using a Win32 Console App. Thanks in advance. Also, can and how do you do the exact same thing with a Win32 app? Both would be nice. Thanks a lot!
I am not worthy of a sig!
I am not worthy of a sig! ;)
Hi,
Will open a text file called readme.txt, and read in an integer from it. If you wanted to read in strings, you need to make a character array big enough to hold the string being read in, and do a similar thing.
If you dont know how long the string is, then assuming your character array is 1024 bytes in size, you can go:
char MyArr[1024];
filein.getline( MyArr,1024 );
This is from memory - im not too sure about the above.
regards,
GeniX
www.cryo-genix.net
#include "fstream.h"void main(){ ifstream filein( "readme.txt" ); int somenumber; filein >> somenumber; filein.close();}
Will open a text file called readme.txt, and read in an integer from it. If you wanted to read in strings, you need to make a character array big enough to hold the string being read in, and do a similar thing.
If you dont know how long the string is, then assuming your character array is 1024 bytes in size, you can go:
char MyArr[1024];
filein.getline( MyArr,1024 );
This is from memory - im not too sure about the above.
regards,
GeniX
www.cryo-genix.net
regards,GeniXwww.cryo-genix.net
Writing to a text file is just like using cout.
==================
/* todo: insert cool sig */
Martee
Magnum Games.NET
ofstream myfile("file.txt",ios::out);myfile << "This will be written to the file" << endl;
==================
/* todo: insert cool sig */
Martee
Magnum Games.NET
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
ofstream fout("outfile.txt");
ifstream fin("infile.txt");
void readafile()
{
char buffer[255];
fin>> buffer;
fin.close();
}
void writefile()
{
char buffer2[10] = {''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1''};
fout<< buffer;
fout.close();
}
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
ifstream fin("infile.txt");
void readafile()
{
char buffer[255];
fin>> buffer;
fin.close();
}
void writefile()
{
char buffer2[10] = {''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1'',''1''};
fout<< buffer;
fout.close();
}
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
Those who dance are considered insane by those who cannot hear the music.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement