简体   繁体   中英

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.

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.

PS- The full code is very long, it is just the beggining of the code,

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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