gpt4 book ai didi

c++ - xxxxx 处的未处理异常无法写入位置。它不会在 getline 之外执行......在 visual studio 2010 中

转载 作者:行者123 更新时间:2023-11-28 00:44:51 25 4
gpt4 key购买 nike

  #include "StdAfx.h"


int main(int argc, char **argv)
{
// using namespace std;
string line;
cout<<"dsadasdas";
fstream file ("D:\source_details.txt", ios::in);
cout<<"dsadasdas"<<endl;

if (file.is_open())
{ cout<<"dsadasdas";
getline (file,line);
cout<<"dsadasdas";
cout<<line;
}
else
{
cout<<"Not possible"<<endl;

}




return (0);
}

代码没有在 getline 之外执行……我收到未处理的异常错误。我不明白我的代码有什么问题。这真的很简单。实际上,这是我试图在 visual studio 中运行的大代码的一小部分,但我一直收到此错误。

最佳答案

fstream file  ("D:\source_details.txt", ios::in);

你需要在这里转义'\'符号,像这样:

fstream file  ("D:\\source_details.txt", ios::in);

关于c++ - xxxxx 处的未处理异常无法写入位置。它不会在 getline 之外执行......在 visual studio 2010 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16767978/

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