简体   繁体   English

C++小猪拉丁语翻译器

[英]C++ pig latin translator

im writing a program in C++ that translates a sentence into pig latin, only by taking the first letter of the word and taking it to the end then and adding "ay" example "hello world" becomes "ellohay orldway" but its not working, ive tried several different ways none are working, at this point im about to give up, please can some one help me do this right.我正在用 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] != '\0')
        count++;
    if (isalpha(input[count]))
        x =input[count];
    if (input[count] == ' ')
        input[count] = (x + ' ');
    if (input[count] == ' ')
        input[count] = 'ay';


}

Your cin >> input;您的cin >> input; is only getting the string up till the first whitespace, so the space between hello and world .只是让字符串直到第一个空格,所以helloworld之间的空间。

That's why it appears to be deleting everything but the first word, you should use something like std::getline (std::cin,input);这就是为什么它似乎要删除除第一个单词之外的所有内容,您应该使用std::getline (std::cin,input);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM