C++pig拉丁文翻译器
C++ pig latin translator
我用C++编写了一个程序,将一个句子翻译成猪拉丁语,只需取单词的第一个字母并将其带到末尾,然后添加"ay"示例"hello world"变为"ellohay orldway",但它不起作用,我尝试了几种不同的方法,但都不起作用。在这一点上,我即将放弃,请有人帮我做好这件事。
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void seperator(char []);
int main()
{
string input;
const int SIZE = 40;
char sent[SIZE];
cout << " enter sentence " << endl;
cin >> input;
cin.getline(sent, SIZE);
seperator(sent);
cout << input << endl;
system ("pause");
return 0;
}
void seperator(char input[])
{
int count = 0;
char x;
while (input[count] != ' ')
count++;
if (isalpha(input[count]))
x =input[count];
if (input[count] == ' ')
input[count] = (x + ' ');
if (input[count] == ' ')
input[count] = 'ay';
}
您的cin >> input;
只获取第一个空格之前的字符串,因此hello
和world
之间的空格。
这就是为什么它似乎删除了除第一个词之外的所有内容,你应该使用类似的词std::getline (std::cin,input);