用v s 2008 学习c++时遇到的问题,请大侠帮忙看看

作者&投稿:姚琛 (若有异议请与网页底部的电邮联系)

我用的vs2010,新建的win32 控制台工程,可以直接通过。

#include "stdafx.h"

#include<iostream>

int _tmain(int argc, _TCHAR* argv[])

{

    using namespace std;

cout << "Come up and C++ me some time.";

    cout << "YOU won-t regret it!" << endl;

return 0;

}

关于namespace。命名空间是用来避免同名的命名冲突的,一般c++中加

#include<iostream>,就要加using namespace std;

但是如果用#include<iostream.h>,就不需要再写using namespace std;

因为加.h便意味着是库文件,直接在库文件中查找了。

初学可以直接在main前写#include<iostream.h>  using namespace std;就行了。

但是如果你想在main中将每个实体类分为不同的命名空间,则需要写作

           int a; std::cout << std::a << 3.4 << std::endl;

这种方法便于debug,不需要的时候,可以把所有标注的cout语句全部取消。



你创建工程时工程的类型选择错了。应该选择“空工程”。

记得采纳~

#include "stdafx.h" //默认需要
#include<iostream>
using namespace std; //不加这个的话, 就要 std::cout这么写
int main()
{
using namespace std;
cout << "Come up and C++ me some time.";
cout << "YOU won-t regret it!" << endl;
return 0;
}

新建一个工程就好了, 要选win32的 ,可以选win32空工程
using namespace::std

或者,直接将#include<iostream>改成#include<iostream.h>呢?

c++习题,请各位大侠帮忙了~

1-4DABC 7-8DC
AB?AB BAC

stack::stack(int top){
top=0;
}
这里传参top没意义,你构造函数要初始化的是自己的成员变量top。

stack::push(int x){
if(top==10){
cout<<"stack is full!"<<endl;
return 0;
}
else a[top]=x;
top++;
}
else后面用花括号括起来吧,虽然这里正好也不会有问题,因为你top==10里面有return.

int stack::pop(){
if(top==0){
cout<<"stack is empty!"<<endl;
return 0;
}
else return a[top];
top--;
}
else后括起来吧。而且return后top--执行不到了,放中括号里或先保存a[top],再top--,再return.