samedi 6 juin 2020

std::ostringstream overwriting initializing string

The following code results in "0004567" on clang++-7

#include <iostream>
#include <sstream>

using namespace std;

int main() {
    ostringstream oss{"1234567"};
    oss << "000";
    cout << oss.str() << endl;
}

Now is this correct STL implementation?

I can't think of how is it useful to initialize with a string that will be overwritten...

Aucun commentaire:

Enregistrer un commentaire