开发者

Printing with fixed spaces

I want to print two strings (say "ABC" and "DEF") with 5 space characters before "ABC" and that the second string will start 7 characters 开发者_如何学运维after the beginning of the first string.


I suspect you're looking for the width() method:

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string abc = "ABC";
  string edf = "EDF";
  cout.width(8);
  cout << abc;
  cout.width(7);
  cout << edf;
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() 
{ 
char a[] = "ABC";
char b[] = "EDF";
cout<"     "<<a<<"       "<<b;
return 0; 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜