
C++ Program to Convert Integer into a String
using namespace std; #include <string> #include <sstream> #include <iostream> template <class T> std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) { std::ostringstream oss; oss << f << t; return oss.str(); } int main() { // the second parameter of to_string() should be one of // std::hex, std::dec or std::oct std::cout<<to_string<long>(123456, std::hex)<<std::endl; std::cout<<to_string<long>(123456, std::oct)<<std::endl; return 0; } /* OUTPUT: 1e240 361100 */
C++ Function To Convert String To Numeric Integer
float stof(const string& str, size_t *idx = 0); double stod(const string& str, size_t *idx = 0); long double stold(const string& str, size_t *idx = 0); int stoi(const string& str, size_t *idx = 0, int base = 10); long stol(const string& str, size_t *idx = 0, int base = 10); unsigned long stoul(const string& str, size_t *idx = 0, int base = 10); long long stoll(const string& str, size_t *idx = 0, int base = 10); unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
C++ Function To Convert Numeric Integer To String
NUMERIC TO STRING string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float val); string to_string(double val); string to_string(long double val);
Leave a Reply