gpt4 book ai didi

c++ - 无法初始化 ifstream "Error reading characters of string"

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:20 24 4
gpt4 key购买 nike

下面给了我奇怪的信息:该消息出现在 ifstream 文本中,(悬停时)路径是完整的 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。不好。

感谢您的回答,即使我仍然收到此消息,代码似乎仍在运行。之前我的代码中还有另一个错误。

我想删除它,但知道这条消息不会阻止代码运行可能会有所帮助。

最佳答案

  1. 如果您使用的路径类似于您所写的“C:\t.txt”——那是不正确的。使用必须使用双反斜杠,如"c:\\t.txt"
  2. 如果您使用绝对路径,则检查是否存在具有这样路径的文件。
  3. 如果您使用相对路径,这取决于您运行代码的位置:从 VS( Debug模式)或只运行可执行文件。

关于c++ - 无法初始化 ifstream "Error reading characters of string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23223934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com