Provlem C++

Hello I have a txt file

1
2
3
4
John Acer, DNB, LT123578
Marisa Kate, Swed, LT64454
David Mode, DNB, LT4464
Black Jack, DNB, LT6565


And I need to construct algorythm that my rsults should look like that
1
2
DNB: John Acer LT123578, David Mode LT4464, Black Jack LT6565
Swed: Marisa Kate, LT64454


How I need to to that??
Last edited on
You can open a file stream and have it read in one character at a time adding each character to a string until you hit a comma. Save 3 words at a time and then re-arrange them into whatever order you need. Then loop that until end of file.
It is possible to get some code? thanks
closed account (Dy7SLyTq)
no. we arent going to write code for you. we can only help you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>

int main()
{
    //create an ifstream object with the file you want to use for input

    //create a collection to hold data of type DNB
    //create a collection to hold data of type Swed
    //if you don't know all the types beforehand, make a collection that
    //    will hold collections     (I'd recommend std::vector for all these collections)

    //while there are lines left to read in the file
        //read a line
        //parse line into three strings based on where the commas are
        //based on the second string, determine which collection to put
        //    the other two strings combined
    //end while

    //output your collections
    return 0;
}
Last edited on
Topic archived. No new replies allowed.