C ++ ofstream文本对话问题。 [英] C++ ofstream text aligment problem.

查看:58
本文介绍了C ++ ofstream文本对话问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对齐文字时遇到问题:



I have problem aligning text:

Student Name           Test Score  Grade
Donald, Duckey               85      B
Goofy, Goof                  89      B
Balto, Brave                 93      A
Smitn, Snow                  93      A
Wonderful, Alice             89      B



我是使用< iomanip> setw的标题和对齐左的功能,但我只能做到这样的事情:


I am using the <iomanip> header for the "setw" and align "left" functions but I only manged to achieve something like this:

Student Name           Test Score  Grade
Donald   ,Duckey            85        B
Goofy    ,Goof              89        B
Balto    ,Brave             93        A
Smitn    ,Snow              93        A
Wonderful,Alice             89        B



这是我的代码:


Here is my code:

outFile << left << setw(9)
<< student[i].studentLName << ","
<< left << setw(10) << student[i].studentFName
<< right << setw(10) << student[i].testScore << setw(9)
<< student[i].grade << endl;





有没有人知道如何修复它?或者可能是不同的方法?



Does anyone have an idea on how to fix it? Or maybe different approach?

推荐答案

我会通过连接名字,逗号,姓氏来建立完整的名称。然后你可以将它作为一个具有预定宽度的项目写入文本文件,逗号将出现在正确的位置。
I would build the complete name by concattenating first-name, comma, last-name. Then you can write this to the text file as one item with predetermined width and the comma will appear at the correct place.


这篇关于C ++ ofstream文本对话问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆