std::string s = "65//3";
std::istringstream indexBlock(s);

for (int i = 0; i < 2; i++) {
    int index = 0;
    indexBlock >> index;
    std::cout << index << std::endl;

I would expect the output of the cout to be:


as I thought the stream iterates through the ints when passing it through '>>'. However the actual output is:


Can someone please explain what is happening and how I might go about changing it to get the desired result.

Thank you.

OK, so a friend answered this for me. It is because istringstream uses whitespace as the delimiter. I'll be using getline() instead so I can set my own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.