나는 사용자가 그 때 문장에서 어떤 정류장든지 제거하고 그 후에 그 문자열에있는 각 개별 단어의 목록을 만들 것입니다 문장을 입력 할 수있는 프로그램을 작성하고 있습니다 그 목록을 콘솔에 출력하기 전에. Project6.exe에서 0x7696B727에서에서프로그램 던지는 예외
처리되지 않은 예외 :
프로그램은 한가 단 1 마침표는 문장에 있지만 더 이상이있는 경우는이 예외를 throw보다으로 완벽하게 작동되는 마이크로 소프트 C++ 예외 : 메모리 위치 0x0022F8B8의 std :: out_of_range.
하고 내가 그것을 던져를 계속 실행하는 경우 :
실행 - 시간 검사 실패 # 0- ESP의 값은 제대로 함수 호출을 통해 저장되지 않았습니다. 이것은 대개 다른 호출 규칙으로 선언 된 함수 포인터로 하나의 호출 규칙으로 선언 된 함수를 호출 한 결과입니다.
제안 사항? 누군가가 요청하기 전에 (그리고, 난 당신이 보통 문장 1 마침표를 알고하지만 난 테스트의 일환으로 1 개 이상으로 할 필요가 여기
는 코드입니다.#include <iostream>
#include <string>
using namespace std
string sSentence; // sets up a string variable called sSentence
int i = 0;
void RemoveFullStop()
{
while(sSentence.find (".") != string::npos) // the program runs this loop until it cannot find any more full stops in the string
{
i = sSentence.find("." , i); // find the next full stop in the string and get the character count of the space and place it in the variable i
sSentence.replace(i,1,""); // remove the full stop
}
}
void ListWords()
{
while(sSentence.find (" ") != string::npos) // the program runs this loop until it cannot find any more spaces in the string
{
i = sSentence.find(" " , i); // find the next space in the string and get the character count of the space and place it in the variable i
// cout << i << endl; // output the contents of iWordSpace to the console (used for debugging - no longer used)
sSentence.replace(i,1,"\n");
// cout << sSentence << endl; // output the contents of iWordSpace to the console (used for debugging - no longer used)
}
}
int main()
{
getline(cin, sSentence); // get user input and store it in sSentence (using the getline function so the .find operation works correctly)
RemoveFullStop(); // calls the RemoveFullStop void function that removes all full stops from the string
ListWords(); // calls the ListWords void function that splits the string into a list of words
cout << endl; // formatting line
cout << "The words that were in the sentence were:" << endl;
cout << endl; // formatting line
cout << sSentence << endl;
cout << endl; // formatting line
system("pause");
return 0;
}
글쎄, 디버거의 코드를 단계별로 살펴 보셨습니까? – OldProgrammer
@OldProgrammer 여기서 한 번의 클릭으로 표준 주석을 여러 번 써야합니다 : -P ... –
while() 루프가 진행됨에 따라'sSentence'와'i'의 값을 출력 할 수 있습니다. 이것은 무슨 일이 일어나고 있는지에 대한 통찰력을 줄 것입니다. – jwd