首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++ primer 里的代码 用什么编译器编译阿,vc++6.0成不?该如何处理

2012-02-06 
c++ primer 里的代码 用什么编译器编译阿,vc++6.0成不?最近开始学c++.c++primer这本书不错。但是里面的代码

c++ primer 里的代码 用什么编译器编译阿,vc++6.0成不?
最近开始学c++.
c++   primer   这本书不错。但是里面的代码用vc++6.0编译,错误一大片。我晕,是我用错了编译器??
例:下面代码:
#include   <iostream>
using   namespace   std;

inline   bool   bit_on(   unsigned   int   ui,   int   pos   )
{
        return   ui   &   (1   < <   pos   );
}

inline   void   bit_turn_on(unsigned   int   &ui,   int   pos)
{
        ui   |=   (1   < <   pos);
}

inline   void   bit_turn_off(unsigned   int   &ui,   int   pos)
{
        ui   &=   ~   (1   < <   pos);
}

inline   void   flip_bit(unsigned   int   &ui,   int   pos)
{
        ui   ^=   (1   < <   pos);
}

inline   bool   bit_off(unsigned   int   ui,   int   pos)
{
        return   !bit_on(ui,   pos);
}

int   main()
{
        unsigned   int   ui   =0xd3;         //   1101   0011   in   binary
                                                            //   bits   are   numbered   from   the   right
                                                            //   starting   at   position   0
        cout   < <   "ui   in   hex:   "
                  < <   hex   < <   ui   < <   '\n ';
        //   turn   on   the   4th   bit   from   the   right
        bit_turn_on(ui,   3);
        cout   < <   "result   should   be   'db ',   it   is   "
                  < <   hex   < <   ui   < <   '\n ';
        //   turn   off   the   4th   bit   from   the   right
        bit_turn_off(ui,   3);
        cout   < <   "result   should   be   'd3 ',   it   is   "
                  < <   hex   < <   ui   < <   '\n ';
        //   flip   the   4th   bit   from   the   right
        flip_bit(ui,   3);
        cout   < <   "result   should   be   'db ',   it   is   "
                  < <   hex   < <   ui   < <   '\n ';
        //   flip   the   4th   bit   from   the   right


        flip_bit(ui,   3);

        cout   < <   "result   should   be   'd3 ',   it   is   "
                  < <   hex   < <   ui   < <   '\n ';
        cout   < <   "4th   bit   should   be   0,   it   is   "
                  < <   bit_on(ui,   3)   < <   '\n ';
        cout   < <   "1st   bit   should   be   1,   it   is   "
                  < <   bit_on(ui,   0)   < <   '\n ';

        return   0;
}

编译后得到了102个不知所云的错误:
c:\program   files\microsoft   visual   studio\vc98\include\errno.h(118)   :   error   C2143:   syntax   error   :   missing   '; '   before   '} '
c:\program   files\microsoft   visual   studio\vc98\include\errno.h(118)   :   error   C2143:   syntax   error   :   missing   '; '   before   '} '
c:\program   files\microsoft   visual   studio\vc98\include\errno.h(118)   :   error   C2143:   syntax   error   :   missing   '; '   before   '} '
。。。。。。。。
问题出在哪呢,请各位前辈指教。


[解决办法]
书里面伪代码比较多~~
[解决办法]
VS2005
[解决办法]
当然可以在VC 下写

那你就试一个最简单的C++程序看
#include <iostream>
using namespace std;

int main(void)
{
cout < < "ui in hex: "
return 0;

}
[解决办法]
C:\Documents and Settings\public\デスクトップ\20061024205546561\4-13.CPP(8) : error C2065: 'vector ' : undeclared identifier


路径名……日文?……
还是因为特殊符号,VC没有识别出来吧。。。


[解决办法]
VC++ 6.0编译器对标准C++的支持是比较差的,
用gcc 2.9.2以上的版本学标准C++吧!
[解决办法]
楼主你把C++源文件的扩展名存成.c文件了吧,
C++源文件必须是.cpp的
[解决办法]
我怎觉得是你的操作系统的问题。
[解决办法]
1.遗漏using namespace std;(c++primer开头介绍的时候说过书中省略此声明)。
2.这个。。貌似errno.h被你在无意中修改过……在118行……检查一下看看
[解决办法]
在VC6里面你少了一个:
using namespace std;
而且可能是日文名的原因吧。我这样就没有问题了。我是在Dev-C++里而试的。

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int ia[ 10 ] = {51, 23, 7, 88, 41, 98, 12, 103, 37, 6 };
int main()
{
vector < int > vec( ia, ia+10 );

sort( vec.begin(), vec.end() );
/*
for(int i=0;i <10;i++)
{
cout < <vec[i] < < " ";


}
cout < <endl;
*/
system( "pause ");
return 0;

}

[解决办法]
扔了VC6吧,换vc2005express或者devcpp
[解决办法]
加个

using namespace std;

如果再看看

热点排行