What is the alternative to itoa() for converting an integer to a string in C++

2 Answers

0 votes
#include <iostream>
#include <string>

int main() {
    int n = 7483;
    
    std::string s = std::to_string(n);
    
    std::cout << s;
}



/*
run:

7483

*/

 



answered Feb 15, 2025 by avibootz
0 votes
#include <iostream>
#include <sstream>
#include <string>

int main() {
    int n = 7483;
    
    std::string s;
    std::stringstream out;
    out << n;
    s = out.str();
    
    std::cout << s;
}



/*
run:

7483

*/

 



answered Feb 15, 2025 by avibootz

Related questions

1 answer 137 views
1 answer 124 views
1 answer 70 views
1 answer 75 views
1 answer 91 views
91 views asked Dec 7, 2022 by avibootz
...