![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 5
| int to string - found method not working I tried the following code to convert an int to a string: Code: int i = 5678; string s; stringstream out; out << i; s = out.str(); Code: cout << out << endl; |
| epb is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Try printing s instead of out and you will probably find that out.str() did not return an empty string.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 11
| you can do lyke this int val=2635; char s[50]; cout<<itoa(val,s,10)<<endl; is that you want? |
| joseCarlos is offline | |
| | #4 |
| Registered User Join Date: Nov 2007
Posts: 29
| |
| JacobN is offline | |
| | #5 | ||
| Registered User Join Date: Oct 2009
Posts: 5
| Quote:
Quote:
| ||
| epb is offline | |
| | #6 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
Code: #include <string>
#include <sstream>
#include <iostream>
int main()
{
using namespace std;
int i = 5678;
string s;
stringstream out;
out << i;
s = out.str();
cout << s << endl;
}
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #7 | |
| Registered User Join Date: Oct 2009
Posts: 5
| Quote:
Code: cout << out << endl; | |
| epb is offline | |
| | #8 | |
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| Quote:
Check this out Code: #include <string>
#include <sstream>
#include <iostream>
int main()
{
using namespace std;
int i = 5678;
string s;
stringstream out;
out << i;
cout << out.str() << endl;
s = out.str();
cout << s << endl;
}
| |
| RockyMarrone is offline | |
| | #9 | |
| Registered User Join Date: Oct 2009
Posts: 5
| Quote:
![]() EDIT: The output is two empty lines, so I guess you can say that the output is not completely empty Last edited by epb; 10-26-2009 at 08:28 AM. | |
| epb is offline | |
| | #10 | ||
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| Quote:
and for your information i m on linux 2.6.29.4 and gcc 4.3.2 Quote:
| ||
| RockyMarrone is offline | |
| | #11 |
| Registered User Join Date: Nov 2007
Posts: 29
| According to this thread: Cocoabuilder - (Dmitry Markman) ostringstream problem with Xcode 3.2 Assuming you're using Xcode, try setting it to build as Release rather than Debug? |
| JacobN is offline | |
| | #12 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #13 | |
| Registered User Join Date: Oct 2009
Posts: 5
| Quote:
| |
| epb is offline | |
![]() |
| Tags |
| int, string, stringstream |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading characters from a string and assigning them to a single char??? | DonGenaro | C++ Programming | 26 | 11-30-2007 03:51 AM |
| Line Counting | 00Sven | C Programming | 26 | 04-02-2006 08:59 PM |
| getting a headache | sreetvert83 | C++ Programming | 41 | 09-30-2005 05:20 AM |
| Quack! It doesn't work! >.< | *Michelle* | C++ Programming | 8 | 03-02-2003 12:26 AM |