Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:40:56+00:00 2026-05-25T06:40:56+00:00

I have a text file containing three columns of numbers; one column each for

  • 0

I have a text file containing three columns of numbers; one column each for the x,y,z coordinates of a bunch of points. All numbers are between 0 and 1.

I have created the following structure:

typedef struct 
{
    double xcd, ycd, zcd;
} point; 

I want to create a size-N array of structures of type point. Then I want to scan the text file line by line and for the nth particle, I want to put in the three numbers on the nth line into the respective xcd, ycd and zcd positions.

Tell me if there is some efficeint way of going about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:40:56+00:00Added an answer on May 25, 2026 at 6:40 am

    Simply do it like has been shown five million billion kajillion times before, using ifstream, vector and various other accouterments.

    ifstream infile("myfile.txt");
    
    // check if file opened successfully
    if (!infile) {
        cerr << "failure, can't open file" << endl;
        cin.get();
        return EXIT_FAILURE;
    }
    
    // the container in which we will store all the points
    vector<point> points;
    
    // a temporary point to hold the three coords in while we read them all
    point tmp;
    
    // read in three doubles from infile into the three coords in tmp
    while (infile >> tmp.xcd && infile >> tmp.ycd && infile >> tmp.zcd)
        // add a copy of tmp to points
        points.push_back(tmp);
    

    This will read in three doubles and put them in a point then put a copy of that point in points. However, if the number of numbers in the file modulus 3 is not 0, it will stop and not add the incomplete point to points.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file containing 10 columns of numbers. What I would like
Hi I have a text file containing two arrays and one value(all integers) like
I have a text file containing 21000 strings (one line each) and 500 MB
I have a text file containing a number of records. Each record is stored
In a text file I will have a line containing a series of numbers,
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a text file containing unwanted null characters (ASCII NUL, \0 ). When
I have a text file containing words separated by newline , like the following
I have a text file containing two or more types of lines. I would
I have a text file (txt) containing formatted text (just line breaks, carriage returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.