Valhalla Legends Forums Archive | C/C++ Programming | ofstream/ifstream

AuthorMessageTime
MoNksBaNe_Agahnim
i was wondering, how would i create/input info/output info from a txt file from a folder...

i.e.

[code]
ofstream fout;

fout.open("text.txt");

fout << "testing";

fout.close();
[/code]

that would make a file called text.txt in my main program folder and input testing in the file...how would i do that if i wanted to create a file into a folder within the main folder and write into it? Would it be that same only...

[code]
ofstream fout;

fout.open("txt files"); // folder already been made called txt files

fout.open("text.txt");

fout << "testing";

fout.close("text.txt");

fout.close("txt files");
[/code]
December 12, 2003, 2:06 AM
Eibro
[quote author=MoNksBaNe_Agahnim link=board=30;threadid=4184;start=0#msg34874 date=1071194777]
i was wondering, how would i create/input info/output info from a txt file from a folder...

i.e.

[code]
ofstream fout;

fout.open("text.txt");

fout << "testing";

fout.close();
[/code]

that would make a file called text.txt in my main program folder and input testing in the file...how would i do that if i wanted to create a file into a folder within the main folder and write into it? Would it be that same only...

[code]
ofstream fout;

fout.open("txt files"); // folder already been made called txt files

fout.open("text.txt");

fout << "testing";

fout.close("text.txt");

fout.close("txt files");
[/code]
[/quote]Close, just specify the directory when creating the file:
[code]
fout.open("text files\\text.txt");
fout << "testing";
fout.close();
[/code]
December 12, 2003, 2:52 AM

Search