char path[80];
cout<<"Enter the path:";
cin>>path;
ofstream myfile;
myfile.open ("");
I would like to know how can i put this char"path" into the brackets in myfile.open.I mean if i cin test.txt how can i put it into brackets. I think it is going to be easier ,than i expect but i can't get it.Thx guys for help
If i recall, I had this similar problem and this is what I found to get it to work. This worked on a file name, not sure if it will work for a path. Try this at least.
std::cin << path; You probably intend to use >> here.
Actually opening file in constructor is just neat looking thing. It does not give any actual benefits (aside from impossibility to use uninitializated stream). Constructor with parameters differs from default one only by call to file.open() at the end on most implementations
I couldnt solve my problem.I dont know what to do.Isnt there easier way to get the content of path to the brackets in opening ? But thanks for the replies
i know but it does not allow me compile while there is no ("path"). and then it makes only a file named path all the time .I hope we are talking about same thing.
My idea is: for example i write in program name of txt file results.txt it makes a file and save results there manualy if i replace ("path") to ("resultst.txt") it works.
this stage is not clear for me especially this (path) in brackets is wrong because compiler says it has to be ("path")
Your compiler does not support C++11. In C++11 there are two versions of ofstream constructor. First takes constchar * as parameter and the second takes const std::string &. Previous C++ had only the first form.
std::string path is not of type const char *. Earliers posters did mention c_str(). That member function of std::string does return a const char *. Therefore: