I meet error "String subscript out of range" when run these codes
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
ifstream in("_start.txt");
ofstream out("_end.txt");
string str;
while (getline(in, str))
{
if ((str[0] != '/') && (str[1] != '/'))
out << str << endl;
}
//getline(in, str);
//if ((str[0] != '/') && (str[1] != '/'))
//out << str << endl;
return 0;
}
File _start.txt is like this
//<3403> 「それじゃまるで…俺おまえのライバルみたいじゃんか…」
<3403> 「It's like...we were actually rivals or something...」
<3403> 「Giống như...chúng ta là đối thủ thật sự hay sao ấy...」
//<3404> 井上
<3404> Inoue
//<3405> 「きっとね」
<3405> 「I'm sure we were.」
<3405> 「Tôi tin là thế.」
My purpose is to check 2 character at start of each line if have "//-character" will be ignored. Then I keep checking 6 characters at start of each line with same format
<[number with at least 4 characters, so number 1 will be written 0001]>
and this line's number is bigger than previous line's number 1. So if this line's number is equal
Add "//-character" at start of previous line
or bigger previous line's number 2, 3 or 4,... (larger than 1) will be fixed.
It is a long way so I started with mini-purpose is to print all lines except lines with "//-character" at beginning and I meet this error. If I do without loop, everything is fine with first line but when I include loop, error appears.