내가 읽고 텍스트 파일이 있습니다첫 번째 문자가 .substr 원인 () 오류
this is an email file with [email protected] and some other text for the test
[email protected]
[email protected]
을 그리고 나는 s는 라인과 전자의 시작입니다 substr (s, e - s)
을 가지고는 끝입니다 나에게 줄 것이다이 :
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_str`entering::substr
Aborted
이것은 단지 아래 두 줄을 발생하고, 첫 번째는
내가 s
이 t 일 때입니다 무슨 일이 일어나고 있는지 알고 문제 [email protected] 인쇄됩니다 그는 라인의 시작 부분에 문자가 없습니다 (예 : "[email protected]"또는 "[email protected]")이 오류가 발생합니다. 이것이 발생하지 않도록 추가 할 수있는 것은 무엇입니까?
while (getline(fin, lines))
{
for (int i = 0; i < lines.length(); i++)
{
if (lines[i] == '@')
{
int s;
if (i == 0 || i == 1) break;
for (s = i - 1; s < lines.length() ; s--)
{
if(validChar(lines[s]) == false)
{
s = s + 1;
break;
}
} //for
int e;
bool hasDot = false;
for (e = i + 1; e < lines.length(); e++)
{
if (e == lines.length()) break;
if(validChar(lines[e]) == false)
{
break;
} // if in for
if(lines[e] == '.') hasDot = true;
} // for
anEmail = lines.substr (s, e - s);
if (s < i && e > i && hasDot == true)
cout << anEmail << endl;
'substr '을 호출하는 코드를 보여줄 수 있습니까? –
우리에게 당신이 사용하고있는 코드를 보여주세요 –