C++程序改错,以下程序哪里出错了,请帮忙指出

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:31:10
编写程序,将字符串str中的所有字符“k”删除
#include"iostream.h"
#include"math.h"
main()
{
char str[100];
int i=0,j=0;
cin>>str;
while(str[i]!='\0')
if(str[i]!='k')
{
s[i]=str[i];
i++;
j++;
}
cout<<s<<endl:
}

#include"iostream.h"
#include"math.h"
main()
{
char str[100],s[100];
int i=0,j=0;
cin>>str;
while(str[i]!='\0')
if(str[i]!='k')
s[j++]=str[i++];
else
i++;
s[j] ='\0';
cout<<s<<endl;
}

#include"iostream.h"改为#include<iostream>
加上using namespace std;
main()前面加个返回类型void。
s[i]使用之前先定义 char s[100];
最后的endl后面的冒号改为分号。

main()
{
char str[100], s[100];
int i=0,j=0;
cin>>str;
while(str[i]!='\0')
{
if(str[i]!='k')
{
s[j++]=str[i];
}
i++;
}
s[j] = '\0';
cout<<s<<endl;
}

main的前面应该加int这是ANSI/ISO确定的,楼上的别教坏别人

没有命名空间,加上using namespace std;
s未定义变量类型,使用之前先定义 char s[100];