Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
OK for any people who are having similar problems with reading in data I now have the answer to my problem. I was trying to use a "file.txt" that I had copied from a different project.

Maybe,

This resulted in a newline character error.

I don't think that was the problem.

I just changed the newline to CR in my example "A6.txt" file, and lloyddean's posted code works fine with no changes. It also works fine with CR-LF line-endings. For example, space-separated or tab-separate input lines would work identically. It even works if you mix the different forms in the same input file:
Code:
April,Joe		3120	12
Matthews,Jocob		4592  39
Garfield,Kitty  8917  33

Lake,Bill  2233  21

Jones,Betty
8912
18
This isn't magic. It's how C++'s stream operators are defined to work. Multiple adjacent whitespace characters (which includes tab, space, CR, LF) are counted as a single delimiter between input values.

Something else was going wrong, but unless you post the exact file you were using, and exactly how you were running the command, it's impossible to figure out the reason for the malfunction. If you don't want to pursue this any further, that's fine.
 
Well thanks lloyddean but you are gravely wrong. I do not know about nodes and I have made an effort to understand the example, around about 17 hours is a lot of time to invest. I have not had any training in computer science and I would like to learn.

Every so often someone gives you correct information "as is" with the hope that the information will be understood properly and will not be used to for a selfish purpose. Those are the people who will never be famous but will help us cure diseases and increase our quality of life.

Note: I do not get the error:

Not enough entries in 'nodes_array' to read next record!
Adjust value of 'MAX_NODE_ENTRIES'

Well, my apologies to you TREERAT as I mistook you as the original poster who had indicated he was taking classes and that this was his homework.

Also thank you for making me aware that my copy/paste of the example was missing the inclusion of its very first header file 'cstdlib'.

An example using features of the C++ Standard Template Library:

Code:
#include <cstdlib>

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

struct node_t
{
    std::string     name;
    int             id;
    int             dist;
};

typedef std::vector<node_t>             nodes_array_t;
typedef std::vector<node_t>::iterator   nodes_itr;

int main(int argc, char* const argv[])
{
    std::ifstream   ifs("A6.txt");
    if ( ifs.is_open() )
    {
        nodes_array_t   nodes_array;

        node_t          node;
        while ( ifs )
        {
            if ( ifs )  ifs >> node.name;
            if ( ifs )  ifs >> node.id;
            if ( ifs )  ifs >> node.dist;
            if ( ifs )  nodes_array.push_back(node);
        }
        
        // --- display all entries of 'nodes_array'

        for ( nodes_itr itr = nodes_array.begin(); itr < nodes_array.end(); itr++ )
        {
            std::cout << itr->name << "\n" << itr->id << "\n" << itr->dist << "\n\n";
        }

        return EXIT_SUCCESS;
    }
    
    return EXIT_FAILURE;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.