Hello all, I am a long time browser and first time poster here. Right now I am a little stuck on my project and could use a little help.

The program opens a .txt file and then reads the data and places the data accordingly. The issue this time compared to most times is that the items I am trying to send to a string have spaces in them. (firstname lastname, adress, phone) So, I am not able to use the regular:

inFile >> name[i] >> address[i] >> phone[i];

Is there anyway I can get this information in from the file as a string or do I have to use a c-string? I have also tried what I have below but the artist outputs everything after instead of only until the location of the double space.

while (!inFile.eof())
    {
        pos = 0;                                    // Sets position to start
        inFile.getline(line, 100);                    // Receives first line as full c-string
        tempStr = string(line);                        // Sets line to a temp string

        ds1 = tempStr.find("  ", 0);                // Finds first double space position after title
        title[ptr] = tempStr.substr(pos, ds1);        // Sets title to substring before double space
        pos = 37;                                    // Sets position to artist
        ds2 = tempStr.find("  ", pos);                // Finds first double space position after artist
        artist[ptr] = tempStr.substr(pos, ds2);        // Sets artist to substring before double space

        cout <<  title[ptr] << " " << artist[ptr];    // Test output
        cout << endl;        

        ptr++;
    }

Thanks for any help possible.

In the line number 9 I can't understand why you hardcode that to 37 ?

pos=dsl;

????

In the line number 9 I can't understand why you hardcode that to 37 ?

pos=dsl;

????

I hard coded it due to how the text file is formatted in columns. I have figured out the problem though. I was used to java and the substr command is (startpos, endpos) and in c++ it is (startpos, len). :\

Thanks anyways.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.