c++ primer 里的代码 用什么编译器编译阿,vc++6.0成不?该如何处理
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
最近开始学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