c++函数如何调用

来源:百度知道 编辑:UC知道 时间:2024/07/04 13:00:07
#include #include #include void hello(string const name){const}void main(){ cout }我想简单调用一下我的小函数,我是初学者。但在visual c++环境下报错。谢谢大家http://hiphotos.baidu.com/qqnumber463228803/pic/item/fd4dd036f6fe84130b55a97a.jpeg
主函数写错了,应该如下
void main()
{
hello("china");

}

void hello(char *n)
{
cout<< n <<endl;
}

void main()
{
hello("china");
exit(0);
}

最好改成这样:
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

void hello(string const name)
{
cout<<"hello!"<<name<<endl;
}

int main()
{
hello("china");
return 0;
}

还有编写C/C++程序时要注意区分大小写!!!!!!!!!

include后面文件名要小写的,不能大写,#include <StdAfx.h> #include <IOSTREAM.H> #include <STRING.H> ,<>里的字母全改成小写的

另外,函数
void hello(string const name)
{
const<<"hello!"<<name<<endl; //是cout而不是const,写错了。
}

改了后,程序可以运行的