简而言之,我是 C++ 的初学者,正在学习字符序列。
这是我的问题:我试图将每个包含偶数个字母的单词更改为一个符号 ( # ),但我认为我正在以一种糟糕的方式解决问题。运行它时我什么也没得到。
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char s[101];
cin.getline(s,101);
int i;
for(int i=0; i<strlen(s); i++)
{
if(strchr(s,' ')) // searching for a space
{}
else
if((strlen(s)%2==0)) //trying to find if the word has an even number
{
strcat(s,"#"); // I'm sticking the # character to the word and then deleting everything after #.
strcpy(s+i,s+i+1);
cout<<s;
}
else
cout<<"Doens't exist";
}
return 0;
}
最佳答案
唯一不包含cout的代码流是
if(strchr(s,' ')) // searching for a space
{}
所以调试这个。
关于c++ - 程序运行后无输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41596627/