python是什么题目。。。
固定长度输出通用格式如下:
cout << right << setw(width) << data << endl;
完整代码:
#include <iostream>
#include <iomanip>
using namespace std;
void outputData(char* data, int width = 10)
{
cout << right << setw(width) << data << endl;
}
void outputData(int data, int width = 10)
{
cout << right << setw(width) << data << endl;
}
void outputData(double data, int width = 10)
{
cout << right << setw(width) << fixed << setprecision(2) << data << endl;
}
int main()
{
int a = 10;
double b = 2333.34333;
char* p = new char[100];
strcpy_s(p,100,"this is a test string, you know?"); //长度大于10的字符串
outputData(a);
outputData(b);
outputData(p);
strcpy_s(p, 100, "white"); //长度不足10的字符串
outputData(p);
return 0;
}