문제

How can i replace this

    itoa(i, buf, 10);
    key1.append(buf);
    key2.append(buf);
    key3.append(buf);

with std::to_string

itoa was giving me an error it was not declared in scope that its not part of standard

I heard i can use std::to_string to make another version of it how do i do this?

도움이 되었습니까?

해결책

If you use C++11, you can use std::to_string

#include <string>
std::string buf = std::to_string(i);
key1.append(buf);
key2.append(buf);
key3.append(buf);

or you could just use std:stringstream

#include <sstream>
std::stringstream ss;
ss << i;
key1.append(ss.str());
key2.append(ss.str());
key3.append(ss.str());

다른 팁

To use itoa() function, you need to include stdlib.h file, then you will not see the error while using itoa().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top