• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

God I hate C++

lukatmyshu

Senior member
Using C++ how would I make a string have the same value as a an float ... so if I have a float x = .5 how do I get a string to have the same value?
 
if you just want to convert the value and not output it, look in your class book or google for "typecasting" or "casting" or "cast"
 
stringstream ss;

float x = .5;

ss << setf(1) << x;

string s = ss.c_str();

// This is close, but may be off a little since I don't have my book in front of me.
 
You hate it because the string class << doesn't override having a float in the picture? Jeez...

I wrote a program which goes through and downloads pictures for comics every day of the year, until they changed it to random numbers, instead of just the dates. That was the life.
 
Just use string streams.
Here's a quick and dirty example:


#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
stringstream x;
float y = 1e29;
string z;
x << y;
x >> z;
cout << z << endl;
return 0;
}
 
Back
Top