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

请们帮忙看一下~

2012-02-11 
请大虾们帮忙看一下~~我想实现输入号码时,如果第一个是0,也能输出,如输入022, 输出的也是022而不是22。请指

请大虾们帮忙看一下~~
我想实现输入号码时,如果第一个是0,也能输出,如输入022, 输出的也是022而不是22。请指教!!
#include <iostream>
using namespace std;

////////////////////////////
struct photo 
{
  int areacode;
int exchange;
int number;
};
////////////////////////////

int main()
{
photo Photo1 = {212, 767, 8900 };
photo Photo2 ;

cout<<"Please enter your area code, exchange, and number: ";
cin>>Photo2.areacode>>Photo2.exchange>>Photo2.number;
 
cout<<"My number is "<<"("<<Photo1.areacode<<") "<<Photo1.exchange<<"-"<<Photo1.number<<endl;
cout<<"Your number is "<<"("<<Photo2.areacode<<") "<<Photo2.exchange<<"-"<<Photo2.number<<endl;;
 
return 0;
}


[解决办法]
都改成字符类型啊 
CString
string
都可以的啊
你说的报错应该是类型不统一吧

探讨
转成字符串输出,在Photo1的初始化的时候,会报错。

[解决办法]
收到之后先判断首位是否为0,用CString类型很方便操作
[解决办法]
cout<<setw(/*宽度*/)<<setfill(/*填充的字符*/)<<.....;
你看可以不....

热点排行