简体   繁体   English

从文件读取并将其存储在数组中

[英]Reading from a file and storing it in a array

I have a txt file which contains 3 columns, i want to store these values in a 1-D array such that values from column 2 & 3 are only stored, not 1. 我有一个包含3列的txt文件,我想将这些值存储在一维数组中,以便仅存储第2&3列中的值,而不是1。

Here's a thought: 这是一个想法:

int main()

{

 double x1=[n];
 double y1= [n];

    std::ifstream fin ("1.txt",std::ifstream::in);

    i=1;
    while(!fin.eof())
    {
        fin>>i>>x1[i]>>y1[1];
        i++
    }

It appears it isn't working? 看来没有用? Any thought where I am wrong and how to improve this? 有没有想到我错了以及如何改善这个问题?

how can i store data in the form of 1-D array from a file which has 3 columns and i need to use just column 2 and 3. I am so confused. 我如何从一个具有3列的文件中以1-D数组的形式存储数据,我只需要使用第2列和第3列即可。我很困惑。

PS- The full code is very long, it is just the beggining of the code, PS-完整的代码很长,只是代码的开始,

Thanks !! 谢谢 !!

Your code contains too many mistakes... 您的代码包含太多错误...

If the first column is index. 如果第一列是索引。

double x1[n];
double y1[n];

std::ifstream fin ("1.txt",std::ifstream::in);

while(!fin.eof())
{
    int i;
    fin >> i;
    fin >> x1[i] >> y1[i];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM