两者作用是一样的,都是设定下一次输出输入宽度,但setw是操作子,而width是成员函数!如const char *str1 = "hello";const char *str2 = "world";cout.width(10);cout<cout.width(10);cout<或者使用:cout<显然使用setw要更方便,不过要包含头文件:#include