setw
似乎没有为我调整这里的东西,我不知道为什么会这样。插入\t
确实会将事情推向右侧,但我希望更严格地控制输出的格式。有任何想法吗?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
string name = "Name LastName";
int age = 27;
double milesRun = 15.5;
ofstream outFile;
outFile.open("text.txt");
outFile << "Person's name: " << name << setw(12) << "Person's age: " << age << setw(12) << "Miles run: " << milesRun << endl;
outFile.close();
return 0;
}