+ 1
Link a file to a project
How do you specify the path of a new file.txt that is not in the same folder with your project when working with files in C++?
2 ответов
+ 2
It sounds like you're trying to read or write a file that isn't in the same directory as the source files of your c++ project.
You can use either relative or absolute paths.
1. Relative: You could use paths like "../../data/file.txt".
2. Absolute: You could use a path like ifstream ifs( "c:/demo.txt" );
or ifstream file;
file.open("C:\\Demo.txt", ios::in);
If you run into any confusing file not found errors, try writing a random file name and finding where it went. It is easy for the current working directory to become different from expected.
0
Thanks a lot it works