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;
}
精彩评论