注册 登录
编程论坛 C++教室

"heloo"程序的错误

lockhawk 发布于 2008-09-18 10:33, 844 次点击
#include "biting"
int main()
{
    cout << "my own world";
    return0;
}



这么简单的程序错在哪??我晕了!!!运行显示hello.exe - 1 error(s), 0 warning(s)

希望大家能帮帮新手哈
14 回复
#2
lockhawk2008-09-18 10:42
麻烦说一下。谢谢
我没老师的
#3
ma35872008-09-18 10:54
#include "biting"
这是个什么东西
#4
lockhawk2008-09-18 11:11
这样子也是错误:
// gohome.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int main(int argc, char* argv[])
{
    cout<<"my own world!";
    return 0;
}

只有这样才行:
#include "stdafx.h"

int main(int argc, char* argv[])
{
    printf("my own world!");
    return 0;
}



为什么cout不能用了?我的书上全是cout的!是《易学c++》
#5
lockhawk2008-09-18 11:14
#6
thanatus2008-09-18 11:40
是这样吧,我也是初学,我觉得可以这样改,
cout和cin是namespace中的标准(std)

也就是说,在c++标准中,你要declare cout和cin这两个对象,修改的方法有两种,如下:
1。在main之前加上:
using namespace std;

2. 或者,加上 using std::cout;using std::cin;也可以。

上述写法是标准写法,应该可以,我没有试过~
#7
lockhawk2008-09-18 12:12
谢谢7楼。但还是不明白:你说的这两句加在哪?
我试过:
using namespace std;
#include "stdafx.h"

int main()
{
    cout<<"3+4";
    return 0;
}

——————————————————————————————

#include "stdafx.h"
using namespace std;
int main()
{
    cout<<"3+4";
    return 0;
}
——————————————————————————
#include "stdafx.h"

int using namespace std;main()
{
    cout<<"3+4";
    return 0;
}
————————————————————————
#include "stdafx.h"

using namespace std;int main()
{
    cout<<"3+4";
    return 0;
}

以上4个都不行。
#8
blueboy820062008-09-18 12:14
LS 说的是对的啊...
cout和cin 都在命名空间std中啊...
#9
blueboy820062008-09-18 12:16
如下两种写法:
#include <iostream>
using namespace std;
int main()
{
    cout<<"3+4"<<endl;
    return 0;
}
---------------------------------------
#include <iostream.h>
//using namespace std;
int main()
{
    cout<<"3+4"<<endl;
    return 0;
}
#10
blueboy820062008-09-18 12:17
这样写也是正确的啊:

#include <iostream>
//using namespace std;
int main()
{
    std::cout<<"3+4"<<std::endl;
    return 0;
}
#11
memoryxy2008-09-18 12:19
#include "stdafx.h"

#include "iostream"

using namespace std;

int main()
{
    cout<<"3+4";
    return 0;
}
#12
thanatus2008-09-18 12:20
下面是两种写法,需要用到iostream头文件,否则编译时不知道如何操作输出

#include <iostream>

using std::cout;
using std::endl;

int main()
{
    cout<<"3+4="<<3+4<<endl;
   
    system("pause");
   
    return 0;
}

或者:

#include <iostream>

using namespace std;

int main()
{
    cout<<"3+4="<<3+4<<endl;
   
    system("pause");
   
    return 0;
}

上面可以在dev-c++4.9.9.2中编译通过~你试试
#13
blueboy820062008-09-18 12:30
#14
lockhawk2008-09-18 12:32
这么多只有12楼的能运行。可能是我的软件坏了,是VC6。0。
#15
thanatus2008-09-18 12:36
我没有用vc6.0,用Dev-c++4.9.9.2吧,事情少,GNU的编译内核~
1