Tags: %TAGME{ tpaction="" web="SCMP118" tag="" }% view all tags

string toString(int i)

A function to convert an int to a string (Since to_string() may not be available on some versions of NetBeans.

The code below shows the funciton with a test driver program.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;
string toString(int i);

int main() {
    int num;
    string sNum;
    cout << "Enter an integer:";
    cin >> num;
    sNum = toString(num);
    cout << sNum << endl;


string toString(int i) {
    stringstream ss;
    string str;
    ss << i;
    ss >> str;
    return str;
Topic revision: r1 - 2018-04-17 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback