text files
is there anyway i can use textfiles i created in a program
because writing cout a bunch of times can get tiring...
text files
is there anyway i can use textfiles i created in a program
because writing cout a bunch of times can get tiring...
ty so so much and why did you double everything ?one for c and one for c++?
where did your post go i found it helpfull
well heres whatWell, I would sure hope so lol.
This is the method I learned, so far.
Use #include <fstream>
Declare variables like
ifstream fin;
ofstream fout;
You connect them to files with the "open" member function.
fin.open("file name");
fout.open("file name");
Close them when your done.
fin.close();
fout.close();
And you can do things like
fin >> variable; ect
A little code:I dunno though. That method might be bad...Code:Code: #include <iostream> #include <fstream> #include <ctype.h> #include <stdlib.h> #include <math.h> static int spaces = 0; using namespace std; void edit_file(ifstream & fin, ofstream & fout); int check_word(ifstream & fin, ofstream & fout); int main() { ifstream fin; ofstream fout; fin.open("C:\\Documents and Settings\\Stephen\\My Documents\\New Folder\\letter.txt"); if(fin.fail()) exit(1); fout.open("C:\\Documents and Settings\\Stephen\\My Documents\\New Folder\\letter2.txt"); if (fout.fail()) exit(1); cout << "Editing..." << endl; edit_file(fin, fout); cout << "Done." << endl; fin.close(); fout.close(); return 0; }
Last edited by lilhawk2892; 07-04-2006 at 10:54 PM.
I thought maybe I read your post wrong.
Anyway...
This is the method I learned, so far.
Use #include <fstream>
Declare variables like
ifstream fin;
ofstream fout;
You connect them to files with the "open" member function.
fin.open("file name");
fout.open("file name");
Close them when your done.
fin.close();
fout.close();
And you can do things like
fin >> variable; ect
A little code:
I dunno though. That method might be bad...Code:#include <iostream> #include <fstream> #include <ctype.h> #include <stdlib.h> #include <math.h> static int spaces = 0; using namespace std; void edit_file(ifstream & fin, ofstream & fout); int check_word(ifstream & fin, ofstream & fout); int main() { ifstream fin; ofstream fout; fin.open("C:\\Documents and Settings\\Stephen\\My Documents\\New Folder\\letter.txt"); if(fin.fail()) exit(1); fout.open("C:\\Documents and Settings\\Stephen\\My Documents\\New Folder\\letter2.txt"); if (fout.fail()) exit(1); cout << "Editing..." << endl; edit_file(fin, fout); cout << "Done." << endl; fin.close(); fout.close(); return 0; }
lol i just posted your post in my edited post thanks by the way
:P
?Originally Posted by lilhawk2892
You mean my headers?
no like
fin.open("file name");
fout.open("file name");
its almost doubled.
it looks like its fin = printf
fout = cout
c c++
Oh...fin and fout are just variable names. Use whatever you want. Its just what my book uses. And fin is of type ifstream, which you use to get input, and fout is of type ofstream, which you use for output.
which book my birthdays on the 28th and i cant get an ipod anymore so i wanna get some c++ books(among other things)
A book from the 80's i think lol. You better get something recent.
lol im thinking of c++ for dummies