我的输出略有偏差。现在我的输出看起来像这样:
Is this correct??
My Project works!!!!
*************** I don't know
我需要它看起来像这样:
Is this correct???
My Project works!!!!!
****************I don't know
空字符/空格对我来说搞砸了所有 3 行,我不确定在这种情况下如何忽略空值。
我的输入文件如下所示:
63-27.8 18spaces L Is this correct
33fill 21b5 l My Project works
42??? 28-09ng5 R I don't know
这是我的代码:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string filename;
int a, b, c; // ASCII values for fill character
int aw, bw, cw; // width values for setwidth
char ch1, ch2, ch3; // character for right or left justification
string s1, s2, s3; // strings
ifstream inData;
cout << "please enter the location of the file you wish to input: " << endl;
getline(cin, filename);
inData.open(filename.c_str());
inData >> a;
inData.ignore(100, ' ');
inData >> aw;
inData.ignore(100, ' ');
inData >> ch1;
getline(inData, s1);
inData >> b;
inData.ignore(100, ' ');
inData >> bw;
inData.ignore(100, ' ');
inData >> ch2;
getline(inData, s2);
inData >> c;
inData.ignore(100, ' ');
inData >> cw;
inData.ignore(100, ' ');
inData >> ch3;
getline(inData, s3);
{
if (ch1 == 'l' || ch1 == 'L')
cout << left;
else if (ch1 == 'r' || ch1 == 'R')
cout << right;
else
cout << "error" << endl;
}
cout << setw(aw) << setfill(char(a)) << s1 << endl;
{
if (ch2 == 'l' || ch2 == 'L')
cout << left;
else if (ch2 == 'r' || ch2 == 'R')
cout << right;
else
cout << "error" << endl;
}
cout << setw(bw) << setfill(char(b)) << s2 << endl;
{
if (ch3 == 'l' || ch3 == 'L')
cout << left;
else if (ch3 == 'r' || ch3 == 'R')
cout << right;
else
cout << "error" << endl;
}
cout << setw(cw) << setfill(char(c)) << s3 << endl;
return 0;
}
你将如何纠正这个问题?