怎么输出以下格式啊

来源:百度知道 编辑:UC知道 时间:2024/09/22 06:55:35
姓名 年龄 性别
张三 12 男
李四 13 男
宋梅 10 女

用c++编写

//以下程序在Windows SP2,VC6.0 SP6编译通过
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

void FormatCout(string str1, string str2, string str3)
{
cout<<setw(10)<<str1<<setw(10)<<str2<<setw(10)<<str3<<endl;//数字10为宽度,可以自己设置
}
int main(int argc, char* argv[])
{
FormatCout("姓名","年龄","性别");
FormatCout("张三","12","男");
FormatCout("李四","13","男");
FormatCout("宋梅","10","女");

system("pause");
return 0;
}

printf("%s\t%s\t%s\n","姓名","年龄","性别");