[英]What is an unhandled exception of type 'System.Runtime.InteropServices.SEHException'
[英]A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in Network Controller.exe
这是我的代码
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main() {
string line;
ifstream myfile("C:\\Part1.txt");
int n = 0;
while (getline(myfile, line))
{
if (line != ""){
if (n > 8){
cout << line.substr(line.length() - (line.length()-27l)) << '\n';
}
}
n = n + 1;
}
myfile.close();
}
我收到以下错误:
网络Controller.exe中发生类型为'System.Runtime.InteropServices.SEHException'的第一次机会异常
附加信息:外部组件引发了异常。
如果有此异常的处理程序,则程序可以安全地继续
我能做什么?
阅读@Sebastian Redl的评论后,^,我认为这可以解决您的问题:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile;
int n = 0;
myfile.open("example.txt");
while (getline(myfile, line))
{
if (line != ""){
if (n > 8){
if (line.length() > 27)
cout << line.substr(line.length() - (line.length() - 27l)) << '\n';
}
}
n = n + 1;
}
myfile.close();
getchar();
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.