This is my code
#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();
}
I'm getting the error of:
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in Network Controller.exe
Additional information: External component has thrown an exception.
If there is a handler for this exception, the program may be safely continued
What can I do?
After reading comment from @Sebastian Redl, ^, i think this will solve your problem:
#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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.