我有一些类型为“文件”的文件 我的意思是代替“Resource \ sample.txt”,他们的名字是“Resource \ sample” 现在我想用c ++读取它们并将它们存储在一个字符串中。 这是我的代码:
std::stringstream textBuffer;
std::fstream fileHandle;
std::string content
fileHandle.open("Resource\sample", std::ios::in);
textBuffer << fileHandle.rdbuf();
content = textBuffer.str();
fileHandle.close();
但是当我编译它时,“content”变量的值等于“”。 帮助我。提前致谢。 请注意,唯一的问题是该文件没有任何扩展名,例如.txt或.dat或.bin。
答案 0 :(得分:10)
您没有正确转义文件名字符串中的反斜杠。
fileHandle.open("Resource\\sample", std::ios::in);