Tunko Development Diary

std::string 형변환 정리. 본문

Development/C++, C++11

std::string 형변환 정리.

Tunko 2017. 10. 11. 19:08
std::string to_str(int t) {
std::stringstream ss;
ss << t;
std::string str = ss.str();
return str;
}
std::string to_str(float t) {
std::stringstream ss;
ss << t;
std::string str = ss.str();
return str;
}
std::string to_str(long t) {
std::stringstream ss;
ss << t;
std::string str = ss.str();
return str;
}
std::string to_str(double t) {
std::stringstream ss;
ss << t;
std::string str = ss.str();
return str;
}
int from_str_to_int(std::string t) {
const char* buffer = t.c_str();
int i = atoi(buffer);
return i;
}
long from_str_to_long(std::string t) {
const char* buffer = t.c_str();
long i = atol(buffer);
return i;
}
double from_str_to_double(std::string t) {
const char* buffer = t.c_str();
double i = atof(buffer);
return i;
}
float from_str_to_float(std::string t) {
const char* buffer = t.c_str();
float i = atof(buffer);
return i;
}


반응형
Comments