标题:为什么不能用cout ?
取消只看楼主
pipiku
Rank: 1
等 级:新手上路
帖 子:49
专家分:2
注 册:2009-3-20
结帖率:87.5%
已结贴  问题点数:10 回复次数:1 
为什么不能用cout ?
#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 编辑 ]
搜索更多相关主题的帖子: cout 
2009-10-05 21:56
pipiku
Rank: 1
等 级:新手上路
帖 子:49
专家分:2
注 册:2009-3-20
得分:0 
回复 5楼 明次
确实缺了using了,谢了
2009-10-07 20:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-287661-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.741175 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved