首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么设置stringstream格式化右补空格

2012-06-05 
如何设置stringstream格式化右补空格?通常情况是这样的:#include stdafx.h#include sstream#include

如何设置stringstream格式化右补空格?
通常情况是这样的:
#include "stdafx.h"
#include <sstream>
#include <iostream>
#include <iomanip>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  std::stringstream str;
  int a = 5;
  str << setw(10) << setfill(' ') << a << endl;
  std::cout << str.str();

return 0;
}
-----------------------------------什么是左边补空格,但如何右补空格?

[解决办法]

C/C++ code
//用*示意#include <sstream> #include <iostream> #include <iomanip> using namespace std; int main() {     std::stringstream str;     int a = 5;     str << setw(10) << setfill('*') << left << a << endl;     std::cout << str.str(); return 0; }
[解决办法]
std::left / std::right

热点排行