Hi all,

I need some help on creating a file with name from user input like from textbox.
i have the following code with the filename in textBox2->Text but i dont know how i can get it done.

string::size_type j = line.find_first_of( " \t", iter );
	string found;
	found = line.substr( iter, (j == string::npos) ? j : (j -iter) );

	 const char * buffer=found.c_str();
	string str (found.c_str());
	 int sizeNum = str.length();
	 long size = sizeNum;\

	ofstream outfile ("temp.txt");
	outfile.write (buffer,size);
	outfile.close ();
								textBox2->Text = System::IO::File::ReadAllText("temp.txt");;

I have tried usng these code but still got error messages, any direction or link will be greatly appreciated.

ofstream newFile (found.c_str()&".txt");
ofstream nnewfile (textBox2->Text &".txt");

how about ofstream newFile(found+".txt");

how about ofstream newFile(found+".txt");

Thanks for your help, i have tried it but it give this error.

error C2664: 'std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const char *' c:\documents and settings\a\my documents\resultlog\resultlog\Form1.h 218

sorry, my fault. I meant:

string filename = found + ".txt";
ofstream(filename.c_str());

sorry, my fault. I meant:

string filename = found + ".txt";
ofstream(filename.c_str());

thank you very much,

I placed your code just after the iterators ends and its works. I still wondering how come it dont work after i retrieved them from the textbox and it still can be shown in messagebox::show but cant passed it as an ofstream string... lol, its weird.

Hi niek_e,

actually i needed to save this .txt inside a folder name Log which is a folder within the same folder of this .exe.

I have tried it as below but cant work.

ofstream(("resultlog//")filename.c_str());

i have done it with the below code;

string filename = found + ".txt";
string dirname = "Log//";
string finaldir = dirname + filename;
ofstream(finaldir.c_str());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.