0

hey what would a basic string program look like, can some one show me? what would I need to do to make the numbers the user inputs in, go into a string?

#include "stdafx.h"
#include <iostream>
#include <ctype.h>
#include <fstream>
#include <string>
using namespace std;
 
int reverseDigit, integer;
 
int main()
{
 cout <<"Please input an integer: " << endl;
 cin >> integer;
 cout << integer << endl;
 return 0;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Infarction
0

The following is copied from the first google result for "c++ int to string":

Q. How do I convert from int to string?

A. Converting from int to string is a little more complicated than converting a string to int. There are no standard C++ functions for this, but there is a way to do it using standard stringstreams. The class stringstream is declared in header sstream and is used like this:

std::stringstream ss;
std::string str;
ss << 31337;
ss >> str;

The variable str now contains "31337"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.