Wednesday, May 8, 2013

Convert an Integer into a String in c++

Convert an Integer into a String  in c++





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;
  system("pause");
  return 0;
} 

----------------------------------------------------------

string to numeric

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);

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);



----------------------------------------------
Easiest way to convert int to string in C++
c++ - Converting an int to std::string
Converting numbers to strings and string - C++
convert between std::string and int - C++
C++ String: How to convert a numeric type to a string
Searches related to Convert an Integer into a String in c++
string to int c++
c++ stdlib h
parse string to int c++
c++ get int from string
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ