Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;猪拉丁语程序中的标点符号_C++_Punctuation - Fatal编程技术网

C++ C++;猪拉丁语程序中的标点符号

C++ C++;猪拉丁语程序中的标点符号,c++,punctuation,C++,Punctuation,所以我正在尝试做一个猪拉丁翻译,到目前为止我的程序还可以运行,但只有一个问题。我不能处理标点符号,因为当输入是一个完整的句子时,如: 我已经讨厌那种“语言”! Otput:我已经准备好“anguagelay”了 我的程序所做的是忽略标点符号,因此它不会出现在输出中。这就是我所拥有的: #include <iostream> #include <cstring> #include <string> using namespace std; bool IsVo

所以我正在尝试做一个猪拉丁翻译,到目前为止我的程序还可以运行,但只有一个问题。我不能处理标点符号,因为当输入是一个完整的句子时,如:

我已经讨厌那种“语言”! Otput:我已经准备好“anguagelay”了

我的程序所做的是忽略标点符号,因此它不会出现在输出中。这就是我所拥有的:

#include <iostream>
#include <cstring>
#include <string>

using namespace std;

bool IsVowel(char letter)
{
switch(letter)
{
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'Y':
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
        return true;

    default:
        return false;
}
}



void PigLatin(char *word)
{
string s1(word);
string s2;

if(IsVowel(word[0]) == true) s2 = s1 + "way";
else s2 = s1.substr(1) + s1[0] + "ay";

cout << s2 << " ";
}

int main()
{
char sentence[10000];
char *words;

cin.getline(sentence, 10000);
words = strtok(sentence, " ,.!:;""?");

while (words != NULL)
{
    PigLatin(words);
    words = strtok(NULL, " ,.!:;""?");
}
return 0;
}
#包括
#包括
#包括
使用名称空间std;
布尔元音(字符字母)
{
开关(字母)
{
案例“A”:
案例“E”:
案例“I”:
案例“O”:
案例“U”:
案例“Y”:
案例“a”:
案例“e”:
案例“i”:
案例“o”:
案例“u”:
案例“y”:
返回true;
违约:
返回false;
}
}
无效拉丁语(字符*单词)
{
字符串s1(单词);
字符串s2;
如果(是元音(单词[0])==true)s2=s1+way;
else s2=s1.substr(1)+s1[0]+“ay”;

cout
strtok
抛出定界符,由于您已经指定了各种标点符号作为定界符,因此您看到的行为是预期的


如果要保留标点符号,请使用
strok(句子“”)
取而代之,然后在
PigLatin
中添加逻辑,以区别对待非字母字符。我能想到的最好方法是在字符串中的字符上写一个for循环,逐个写出,用特殊逻辑处理第一个和最后一个字母字符。

你需要问一个特定的问题这个问题太宽泛了,像“我该怎么做?”请尝试一个解决方案,然后在遇到麻烦时问一个具体的问题。为什么要同时使用STD::字符串和char数组?而且永远不要使用Strutk。因为我是C++新手,只学习使用什么和不做什么。我只是尝试使用不同的东西,以便找到一些有用的东西。/如果在
开关之前使用
std::tolower
std::touper
,则代码>减半。