将文件的 const char* 地址传递给 ifstream 对象的问题

Problems of passing a const char* address of file to an ifstream object

ifstream 对象采用 const char*。我正在为我的 ifstream 对象提供我的文件路径

ifstream in_file("E:\myfile.csv"); //File opens

如果我想传递一个包含我的文件地址的字符串,我必须先将其转换为 const char*,我这样做是这样的:`

string mystr="\"E:\\myfile.csv\"" //mystr contains address 
const char* c = mystr.c_str();      //conversion of std::string to const char*

问题就出在这里,

in_file(c);                      //cout << c; gives E:\myfile.csv

我在上述步骤中遇到错误...无法弄清楚哪里出了问题。我正在研究 windows

编辑:我没有收到错误,只是文件没有加载

if (in_file.is_open())
    cout << "opened";
else
    cout << "not opened";

我得到"not opened"

使用

string mystr="E:\myfile.csv";

而不是

string mystr="\"E:\\myfile.csv\"";