I'm failing to open a .txt
file using std::ifstream file
and file.open()
. I want to use an indirect PATH (starting in the folder the .exe
file is in - \\program_folder
), but using a complete PATH ( C:\\Users\\Rafael\\Desktop\\C++\\program_folder\\inputs\\test.txt
) also didn't work.
#include <iostram>
#include <vector>
#include <string>
#include <fstream>
int main(){
char c;
std::vector<std::string> inputs;
inputs.push_back("C:\\inputs\\test.txt");
int a; int b;
std::ifstream file;
file.open(inputs[0]);
if (file.is_open()){
c = file.get();
file.close();
}
else {std::cout << "\nfail to open file";}
}
As output, I'm getting the fail massage.
"C::\\\\inputs\\\\test.txt"
was not a relative path i had to use "inputs\\\\test.txt"
thanks to john in the comments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.