我必须将函数 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;
}