c++ - 程序运行后无输出

标签 c++

简而言之,我是 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/

相关文章:

c++ - 在基类/派生类中调用 C++ 的纯虚函数

c++ - 将共享库与 GCC 链接时出现问题

c++ - 你如何从一个更大的函数创建一个更小的函数?

c++ - SSE:reinterpret_cast<__m128*> 而不是 _mm_load_ps

c++ - C程序反向读取BOM(向左...不!另一个向左)

c++ - 上传到粘贴站

c++ - std::is_function 是如何实现的?

c++ - 如何使用 thrift C++ API 在 HBase 中存储字节数组(Mutation Struct 中的值是 Text ...)

c++ - 错误 : implicitly deleted because the default definition would be ill-formed (vector of structs)

c++ - 如何在 fork 的帮助下并行搜索文件中的字符串? (GNU Linux/g++)