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

为什么不能用cout ?

pipiku 发布于 2009-10-05 21:56, 2030 次点击
#include<iostream>
#include<cstdlib>
#include<cstring>

const int max=10;
class Char{
   char a[max];
   public :
   Char();
   Char(char x);
   void print() const;
};
inline Char::Char(){
     memset(a,'0',max);   
}
inline Char::Char(char x){
     memset(a,x,max);
}
void Char::print() const {
     int i;
    for (i=0; i<max; ++i)
    printf("%c  ",a[i]);
       cout<<a[i];
   // printf("%c  ",a[i]);
   // cout<<endl;
}
int main(){
  Char xx('x');
  xx.print();
  system("pause");
}
为什么print()中用printf可以,用cout却不可以呢?
还有就是把xx初始成Char xx();就会有错误呢?实在是不明白啊

[ 本帖最后由 pipiku 于 2009-10-5 21:58 编辑 ]
5 回复
#2
水云逸2009-10-05 22:28
命名空间std
或者你需要用using声明
#3
flyingcloude2009-10-05 23:49
加using namespace std
#4
yxb00012009-10-06 00:24
缺:using namespace std;
#5
明次2009-10-06 13:13
楼上几个都说对了,缺少using namespace std;
#6
pipiku2009-10-07 20:29
回复 5楼 明次
确实缺了using了,谢了
1