一个简单的C++程序出错问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 19:14:56
#include<iostream.h>
void main()
{
const int size=80;
char buf[size];
cout<<"enter a sentense:\n"<<endl;
cin.read(buf,20);
cout<<"the setense entered was:\n";
int count=cin.gcount();
cout.write(buf,count);
cout<<endl;
}
编译时没错,但连接执行时就出错了.错误提示为:
error LNK2005: _main already defined in 用getline()输入字符串.obj
Debug/用getline()输入字符串.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
请高手帮忙解决一下,非常感谢!!

我用的Visual C++6.0就可以运行啊,没有错误,是不是你的编译器的问题?

我VC6.0可以运行

#include<iostream>
using namespace std;
void main()
{
const int size=80;
char buf[size];
cout<<"enter a sentense:\n"<<endl;
cin.read(buf,20);
cout<<"the setense entered was:\n";
int count=cin.gcount();
cout.write(buf,count);
cout<<endl;
}
这样就没问题了。

main()函数重定义?

很久没用VC6.0了,我曾经用过,并出现过此问题,解决:
项目属性 连接(Linker) 输入(Input) 在里面有个Ignore Specific Library,你输入"MSVCRTD.lib",确定
试试吧

经编译没有错误,是不是在一些标准的c++编译器上会有些不同,你最好加上using namespace std;
我用的是cfree,编译通过,运行也正确,