0

I have been looking for a good approach to solve this issue, but many examples are when words are separated by spaces and it makes a solution easier, like in this example:

ifstream fin(“marks.txt”);

    string name;
    int var1;
    int var2;
    int var3;

    while (fin >> name >> var1 >> var2 >> var3)
    {
        /* do something with name, var1 etc. */
        cout << name << var1 << var2 << var3 << “\n”;
    }

but what if my file has the following:

word1,word2,word3,word4,word5
word6,word,word,word,word,word

How should implement a code for this! I will appreciate any help, newbie in c++ Thanks in advance

Fantom
  • 1
  • 2
  • yeah kind of, but i am not sure how to split by words if the are separated by commas – Fantom Oct 05 '20 at 08:55
  • 1
    In that post, [this answer](https://stackoverflow.com/a/236803/10871073) gives code that can use *any* character as a delimiter. The example uses `:` but it is trivial to change that to a comma. – Adrian Mole Oct 05 '20 at 08:59

0 Answers0