【发布时间】:2014-04-20 17:13:24
【问题描述】:
我必须将函数 p1() 重写为 p2() 以完全模仿 p1(),仅使用 <iomanip> 并且我不断收到该状态的错误
long long unsigned int类型的无效操作数和二进制operator<<的“未解析的函数类型”
代码在这里:
void p1()
{
printf("Size of different basic C++ data type in number of bytes\n\n") ;
printf("size of int = %d \n", sizeof (int) ) ;
printf("size of long = %d \n", sizeof (long) ) ;
printf("size of short = %d \n", sizeof (short) ) ;
printf("size of unsigned int = %d \n", sizeof (unsigned int) ) ;
printf("size of char = %d \n", sizeof (char) ) ;
printf("size of wchar_t = %d \n", sizeof (wchar_t) ) ;
printf("size of bool = %d \n", sizeof (bool) ) ;
printf("size of float = %d \n", sizeof (float) ) ;
printf("size of double = %d \n", sizeof (double) ) ;
printf("size of long double = %d \n", sizeof (long double) ) ;
printf("size of int ptr = %d \n", sizeof (int *) ) ;
printf("size of double ptr = %d \n", sizeof (double *) ) ;
printf("size of char ptr = %d \n", sizeof (char *) ) ;
printf("====================================\n\n") ;
}
这里是 p2() 我必须使用 <iomanip>:
void p2()
{
cout<<"Size of different basic C++ data type in number of bytes\n\n";
cout<<setw(10)<<"size of int"<<"= %d" ,sizeof (int)<<endl;
cout<<setw(10)<<"size of long"<<"= %d" ,sizeof (long)<<endl;
cout<<setw(10)<<"size of short"<<"= %d", sizeof (short)<<endl ;
cout<<setw(10)<<"size of unsigned int"<<"= %d", sizeof (unsigned int)<<endl;
cout<<setw(10)<<"size of char"<<"= %d", sizeof (char)<<endl;
cout<<setw(10)<<"size of wchar_t"<<"= %d", sizeof (wchar_t)<<endl;
cout<<setw(10)<<"size of bool"<<"= %d", sizeof (bool)<<endl;
cout<<setw(10)<<"size of float"<<"= %d", sizeof (float)<<endl;
cout<<setw(10)<<"size of double"<<"= %d", sizeof (double)<<endl;
cout<<setw(10)<<"size of long double"<<"= %d", sizeof (long double)<<endl;
cout<<setw(10)<<"size of int ptr"<<"= %d", sizeof (int *)<<endl;
cout<<setw(10)<<"size of double ptr"<<"= %d", sizeof (double *)<<endl;
cout<<setw(10)<<"size of char ptr"<<"= %d", sizeof (char *)<<endl;
cout<<setfill('=')<<setw(40)<<"="<<endl;
}
【问题讨论】:
-
你有什么问题?
-
我的问题是为什么我会收到错误提示“p2() 中的类型为 'long long unsigned int' 的无效操作数
-
<<"= %d",你觉得这应该怎么做?踢那些部分!
标签: c++ formatting iomanip