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?

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

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.