したがって、これは実行時にエラーを返しますが、デバッガーにはエラーは表示されません。
デバッグ アサーションに失敗しました!
式: 文字列の添え字が範囲外です。
プログラムがアサーション エラーを引き起こす方法については、アサートに関するビジュアル C++ ドキュメントを参照してください。
int main()
{
// declaring variables
string input = "";
int firstChar;
// process:
cout << "Please enter a valid sentence (with spaces):\n>";
getline(cin, input);
cout << "first char is " + input[0] << endl << endl;
firstChar = input.length();
cout << "last char is " + input[firstChar];
// stop and return success
getchar();
return 0;
}