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:

output:
65
3

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

output:
65
0

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.