c++ - Having trouble processing a file from my documents in my code? -
i have searched around web , here can't seem figure out doing wrong.
i trying better file processing , c++.
for practice trying grab text file game folder , make copy of it.
here code (that can't access file).
#include <fstream> #include <iostream> #include <string> using namespace std; int main() { //define / open files ifstream my_input_file; ofstream my_output_file; string filepath = "c:/users/david laptop/documents/my games/oblivion/renderinfo.txt"; my_input_file.open(filepath); if (my_input_file.is_open()) { cout << "opened\n"; my_output_file.open("output_file.txt", ofstream::trunc); char c; my_input_file.get(c); while (my_input_file) { my_output_file.put(c); my_input_file.get(c); } my_input_file.close(); my_output_file.close(); } else { cout << "fail\n"; } cin.get(); return 0; }
this seemed work both text files , .ini files when in project directory having issues getting other directiorys?
any ideas?
thanks!
your code valid , works - tried with own file instead of yours, in line
string filepath = "c:/users/david laptop/documents/my games/oblivion/renderinfo.txt";
so you have not such file or it not in given path or have not such path.
correct in line , ok.
tip: find file in windows explorer, press (and keep pressing)
shift
) , right-click on file. context menu choosecopy path
, paste code. carefull - have change every backslash (\
) forward slash (/
) (as in code) or use double backslashes (\\
) instead of single one.
Comments
Post a Comment