how to create a text file in C++
i dont know of the code… but i will look after this post… BUT..to start off with instead of putting it on A desktop put it one everybodys desktop… it is easier.. and quickeer….
C:\docuemnts and settings\allusers\desktop
OR you could use the short crap
C:\DOCU~!\ALL U~!\Desktop\
i WILL have the code in a few monis hold on
OKAY!
it was ONE simpkle google search ¬_¬..
// text_write.cpp // compile with: /clr using namespace System; using namespace System::IO;
int main() { String^ fileName = "textfile.txt";
StreamWriter^ sw = gcnew StreamWriter(fileName); sw->WriteLine("A text file is born!"); sw->Write("You can use WriteLine"); sw->WriteLine("…or just Write"); sw->WriteLine("and do {0} output too.", "formatted"); sw->WriteLine("You can also send non-text objects:"); sw->WriteLine(DateTime::Now); sw->Close(); Console::WriteLine("a new file ('{0}') has been written", fileName);
return 0; }
THATS FOR VISUAL C++
// compile with: /clr
using namespace System;
using namespace System::IO;
int main()
{
String^ fileName = "textfile.txt";
StreamWriter^ sw = gcnew StreamWriter(fileName);
sw->WriteLine("A text file is born!");
sw->Write("You can use WriteLine");
sw->WriteLine("...or just Write");
sw->WriteLine("and do {0} output too.", "formatted");
sw->WriteLine("You can also send non-text objects:");
sw->WriteLine(DateTime::Now);
sw->Close();
Console::WriteLine("a new file ('{0}') has been written", fileName);
return 0;
}
SORRY FOR POSTING LOADS I AM ONLY TRY TO HELP
Hi,
if you simply want a code snipped in standard C++ (not tested):
#include <fstream>
using namespace std;
int main () {
ofstream MyFile;
MyFile.open ("test.txt");
MyFile << "Writing this to a file.\n";
MyFile.close();
return 0;
}```
This link could be very useful: [http://www.learn-programming.za.net/programming_cpp_learn09.html](http://www.learn-programming.za.net/programming_cpp_learn09.html)
hmmm… heres a summary: http://www.cplusplus.com/doc/tutorial/files.html
@CyberSpider: np man, youre welcome :)
You may consider this link (http://www.codeproject.com/cpp/TextEdit.asp) if you are planning to do a complete GUI app for text editing… ;)