我投入文件,
AMZN~Amazon.Com Inc~1402.05~+24.10~+1.75%~4854900~6806813~01/26/18~1523
AAPL~Apple Inc~171.51~+0.40~+0.23%~39128000~6710843~01/26/18~1224`
我的法典,
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string line1[30];
string line2[30];
ifstream myfile("sp03HWstock.txt");
int a = 0;
if(!myfile)
{
cout<<"Error opening output file"<<endl;
system("pause");
return -1;
}
cout
<< left
<< setw(10)
<< "Stock Name "
<< left
<< setw(5)
<< " Value "
<< left
<< setw(8)
<< "Quantity "
<< left
<< setw(5)
<< " Total Worth "
<< endl;
while(!myfile.eof())
{
getline(myfile,line1[a], ~ );
cout
<< left
<< setw(10);
cout<< line1[a];
}
}
希望产出
Stock Name Value Quantity Total Worth
Amazon.Com Inc 1402.05 +24.10 6806813
Apple Inc 171.51 +0.23% 6710843
产出一
Stock Name Value Quantity Total Worth
AMZN Amazon.Com Inc1402.05 +24.10 +1.75% 4854900 6806813 01/26/18 1523
AAPLApple Inc 171.51 +0.40 +0.23% 39128000 6710843 01/26/18 1224`
我正在使用线索(Mfile,line1[a], ~ );分成几条,我无法进一步分裂。 请允许我帮助我说一下。 感谢!