1
을 두 번 입력하면 askyay askyay
을 다시 얻는 대신 ask askyay
이 나옵니다.돼지 라틴어, for 루프, 문자열 문제
dog
을 두 번 입력하면 ogday ogday
이 아닌 og dogday
이 표시됩니다.
내가 잘못하고있는 것이 확실하지 않습니다. 당신이
new_word = message + "yay ";
가에 발생합니다 "님" "야호"를 추가 또는 다음 단어를 분할하지 않기 때문에
#include <iostream>
#include <string>
#include <cctype>
#include <sstream>
using namespace std;
int main()
{
string vowels = "aeiou";
string new_word;
string pig_message;
string message;
getline(cin, message);
for (unsigned int i = 0; i <= vowels.length(); i++)
{
if (message[0] == vowels[i])
{
new_word = message + "yay ";
cout << new_word;
}
else if (!message[0] == vowels[i])
{
pig_message = message.substr(1) + message[0] + "ay";
cout << pig_message;
}
}
system("pause");
return 0;
}
표준 :'로의 getline() '공간을 포함하는 모든 라인을 판독을 초래할 것이다. 개인적으로 나는 그 행동을 좋아하지만 그 공간을 다루는 것을 기억해야합니다. 또는'std :: cin >> message'를 사용하여 공백으로 구분 된 단어를 읽을 수 있습니다. –