954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Input Formatting issues

Hi-- I am new to C++ and am having trouble with this program: The objective is to take input from a file and write it to output, using the '|' character as the delimiter, but displaying it using a comma (ex, if line 1 is "1000|6 1 6 5 3 2 | Paramus | NJ", the output would be "1000, 6 1 6 5 3 2, paramus, NJ". (the six random numbers are supposed to be test question responses, but that's largely irrelevant.) What i have so far is as follows:

ifstream reader;
    reader.open("SurveyResponse.txt");

    char line[15];
    int i=0;
    while( !reader.eof() )
    {
           reader.getline(line, 15, '|');
           cout << line[i] <<", ";
    }


What i am having trouble with is succesfully extracting each element into the char array, and determining when to insert a new line. Is there any other way than getline to accomplish what i need to do?

doomsday1216
Newbie Poster
7 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Try reading each character instead of the whole line. Then when you read the | or \n you can do your special magic.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: