我正在尝试编写一个 C++ 程序,但我不熟悉 C++。我有一个.txt
文件,其中包含如下值:
0
0.0146484
0.0292969
0.0439453
0.0585938
0.0732422
0.0878906
我在 C++ 代码中所做的如下:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string line;
ifstream myReadFile;
myReadFile.open("Qi.txt");
if(myReadFile.is_open())
{
while(myReadFile.good())
{
getline(myReadFile,line);
cout << line << endl;
}
myReadFile.close();
}
return 0;
}
我想让程序的输出成为一个数组,即
line[0] = 0
line[1] = 0.0146484
line[2] = 0.0292969
line[3] = 0.0439453
line[4] = 0.0585938
line[5] = 0.0732422
line[6] = 0.0878906