无法初始化 ifstream "读取字符串字符时出错"
can't initialize ifstream "Error reading characters of string"
下面给了我一个奇怪的消息:该消息显示在ifstream文本中(悬停时)path是一个完整的windows风格的路径,例如:"C:\t.txt"
void checkInput(string path)
{
ifstream text(path);
// "...<Error reading characters of string.>..."
if (text.is_open())
{
if (text.good())
...
完整信息:
{_Filebuffer={_Set_eback=0xcccccccc <Error reading characters of string>.
_Set_egptr=0xcccccccc <Error reading characters of string>. ...} }
std::basic_ifstream<char,std::char_traits<char>> "
我试着用char*代替字符串,并用string.c_str。不好。
对于答案,尽管我仍然收到这条消息,但代码似乎仍在运行。之前我的代码中有另一个错误。
我想过删除它,但知道这条消息不会阻止代码运行可能会有所帮助。
- 如果您使用的路径像您写的"C:\t.txt"一样,这是不正确的。Use必须使用双反斜杠,如"c:\\t.txt"
- 如果使用绝对路径,则检查文件是否存在这样的路径
- 如果您使用相对路径,这取决于您在哪里运行代码:从VS(调试模式)还是只运行可执行文件
相关文章:
- 分段 使用 MPI_Gather 收集字符数组时出错
- 将常量字符* 转换为字符时出错
- 读取字符串C++的字符时出错
- 为什么常量字符*到常量字符转换出错?
- 读取字符串字符时出错 - 对于数组中的字符串值
- 通过字符串::插入插入字符时出错
- 读取字符串字符时出错
- 计算字符串中字符的出现次数时出错
- C++ 使用 Strtok 读取字符串字符时出错
- C++:使用 fgets() 读取字符输入时出错
- C ++ ifstream 无法读取字符串,并且在读取字符时出错
- 尝试将常量字符 [] static_cast<>为无符号字符 * 时出错
- 从字符串中读取字符时出错
- 英特尔 TBB,parallel_pipeline,当我在阶段之间传递常量字符*时出错
- 转换(常量字符*)变量出错
- 为什么我从字符转换为字符时出错
- 读取字符串C++的字符时出错
- wcscpy_s后读取字符串字符时出错
- 读取字符串 的字符时出错.分配内存
- C++字符出错