How can I read a txt file separated by commas c++ [duplicate]

  c++, fstream, txt, vector

Until now I always had txt files that were ordered like this:

0.23432
0.12232
0.56765 

For this I could simply use this code

    std::vector<double> Readseq;
    std::ifstream myfile;
    myfile.open(FileName);
    if (!myfile)
    {
        std::cout<<"Error, cannot open recordingdata.txt n";
    }
    if(myfile.is_open()){
       while (myfile>>element){
           Readseq.push_back(element);
        }
    }
    myfile.close();

However, I now have text files that are structured like this:
0.123213,-0.12343,0.123123 (Without any line breaks).
How can I read this data into my std::vector<double> Readseq?

Source: Windows Questions C++

LEAVE A COMMENT