String to integer & integer to string

String to integer

int str2int (const std::string &str)
{
    std::stringstream ss(str);
    int n;
    ss >> n;
    return n;
}

Integer to string

string int2str (int n)
{
    std::stringstream ss;
    ss << n;
    return ss.str();
}
programming/c-cpp/strtoint.txt · Last modified: 2018-06-21 19:48 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0