if i entered "123456", how to wirte the syntax for openning the file 123456.txt?Code:char id[10]; cout << "enter file name" cin.getline(id,10);
if i entered "123456", how to wirte the syntax for openning the file 123456.txt?Code:char id[10]; cout << "enter file name" cin.getline(id,10);
use strcat() from string.h or cstring. Look it up in your helpfiles.
Make an attempt. If you find its broken and u cant fix it then repost in this thread.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
if i entered 123456,Code:char id[10]; cout << "please enter the file name:"; cin.getline(id,10);
what i mean is how to write the syntax so that the progam can reconize what i type as:
ifstream file1(C:\\dir1\\dir2\\123456.txt) ???
strcat() is to combine two string right??so i think it is different from what i am trying to do.....
well dont you think strcat(input,".txt"); might be a good starting point?
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
while the output of buf1 is "C:\testing\script\data\565656.txt"Code:char id[10]="565656"; char buf1[100] = "\"C:\\testing\\script\\data\\"; strcat(buf1,id); strcat(buf1,".txt\""); cout << buf1 ; ofstream filex(buf1); filex << "testing"; filex.close();
but the file have not created in the directory.
is the problem happened in ofstream filex(buf1)???
problem fixed....i should not add the " sign at the beginning and the end of C:\.........
all you needed to do was put it into a string and then use the + operator to add the ".txt"
C++ can hurt.
i have tried that before but it cant......
or can you send me the code?
for example
and so onCode:fstream instream; string filename; string name; cin>>name; string addon = ".txt"; filename = name + addon; instream.open(filename.c_str()) ...
C++ can hurt.
Don't confuse the poor guy with STL...he should atleast implement his own String class first
gg