可能であれば、このメールパーサーについてサポートをお願いします。
このコードには適切な宣言と初期化がすべて含まれていますが、このループをどこで混乱させているのかわかりません。
while ( getline( fin, lines ) )
{
for ( int i = 0; i < lines.length( ); i++ )
{
if ( lines[ i ] == '@' )
{
for ( s = i; s < lines.length( ); s-- )
{
if ( s < 0 )
{
break;
}
if ( validChar( lines[ s ] ) == false )
{
break;
}
} //for
for ( e = i; e > lines.length( ); e++ )
{
if ( e == lines.length( ) )
{
break;
}
if ( validChar( lines[ e ] ) == false )
{
break;
}
if ( lines[ e ] == '.' )
{
hasDot = true;
}
} // for
anEmail = lines.substr( s, e );
cout << anEmail << endl;
}
} // if
} // while
そしてこれは関数のためのものです:
bool validChar( char a )
{
bool result = false;
if ( a >= 'A' && a <= 'Z' || a >= 'a' && a <= 'z' || a >= '0' && a <= '9' || a == '.' || a == '-' || a == '+' )
{
result = true;
}
return result;
}
編集:テキストファイル内のこの文字列であるテストケース「これはDummyTest@my.testとテスト用の他のテキストを含む電子メールファイルです」、私はこの「DummyTest@my.test」が欲しいです、そして私はただ得ていますこの「@my.testとその他のテスト用テキスト」
どこが間違っているのですか?