c++中的指针问题
来源:百度知道 编辑:UC知道 时间:2024/09/14 14:05:01
#include<iostream>
#include <cctype>
int main()
{
char hb[]="happy birthday";
showalluppers(hb);
return 0;
}
void showalluppers( char* const str)
{
int i=0;
while(*(str+i))
{
*(str+i)=std::toupper( *(str+i));
i++;
}
std::cout<<str;
}
哪位帮忙看一下那里错了,谢谢了。
#include <cctype>
int main()
{
char hb[]="happy birthday";
showalluppers(hb);
return 0;
}
void showalluppers( char* const str)
{
int i=0;
while(*(str+i))
{
*(str+i)=std::toupper( *(str+i));
i++;
}
std::cout<<str;
}
哪位帮忙看一下那里错了,谢谢了。
程序没有错啊,只是你把main放到了最前面,所以,要先声明一下showalluppers这个函数:
#include<iostream>
#include <cctype>
void showalluppers( char* const str);
int main()
{
char hb[]="happy birthday";
showalluppers(hb);
return 0;
}
void showalluppers( char* const str)
{
int i=0;
while(*(str+i))
{
*(str+i)=std::toupper( *(str+i));
i++;
}
std::cout<<str;
}
#include<iostream>
#include <cctype>
using namespace std;
int main()
{
void showalluppers( char* const str);//在这里加上子函数的声明
char hb[]="happy birthday";
showalluppers(hb);
return 0;
}
void showalluppers( char* const str)
{
int i=0;
while(*(str+i))
{
*(str+i)=toupper( *(str+i)); //这里写为toupper,不需要写为std::toupper
i++;
}
std::cout<<str;