Pregunta

I have an example string:

test1\0test2\0test3\0

And I want to be able to copy it to a stringstream. I've tried the following methods which are not working:

sStream << teststring;
sStream.write(teststring, 99);

Is there a simple way to copy text to a stringstream while ignoring null characters?

¿Fue útil?

Solución

Are you using std::string like Kerrek SB? It becomes as simple as the following:

int main()
{
    std::ostringstream ss;
    std::string testString("a\0b\0c\0d", 7);

    ss.write(&testString[0], testString.size());

    std::cout << ss.str(); // abcd
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top