C语言没有string类型
你可以改成这样,用char *来表示string就可以了
#include
#include
#include
char * a(char * s)
{
s="这里是子函数";
return s;
}
void main()
{
char *b;
b = (char *)malloc(sizeof(char *));
printf("%s",a(b));
printf("这里是主函数\n");
}
C语言没有String这个类型。
可以改成:
#include
#include
char * a(char * s)
{
s="这里是子函数";
return s;
}
void main()
{
char *b;
b = (char *)malloc(sizeof(char *));
printf("%s",a(b));
printf("这里是主函数\n");
}
#include
using namespace std;
string a(string s)
{
s="这里是子函数";
return s;
}
int main()
{
string b="123";
// printf("%s",a(b));
cout< printf("这里是主函数\n");
return 0;
}
改成上面这样就可以正确输出子函数中的语句了,不能够用printf函数输出,这是因为string字符串类型是定义在命名空间std中的一个结构体类型,类型定义为:struct std::string,只能用std命名空间上的输入输出流运算符来输出string类型的字符串。C语言中没有字符串类型的,其对字符串的处理是通过字符数组来实现的。
你这程序是错误的!!!!