Feb 27, 2015 at 3:02pm UTC
Hey Guys!
I'am just trying to write my function to converting from int value to string .
it seems it'll work , but there is some problem , can any body help !
here's my code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str(30, '\0' );
int counter=0,x,c;
float fl,fll;
cin>>x;
fl=x;
c=x;
while (c>=1)
{
c=c/10;
counter++;
}
for (int i=counter-1;i>=0;i--)
{
str[i]=(int )((fl/10-x/10)*10)+48;
x=x/10;
fl=x;
}
cout<<str<<endl;
}
it does't return the correct value ,
like :
input = 123456789
output = 12345577:
or
input = 2587
output = 2586
just like that ..
Last edited on Feb 27, 2015 at 3:10pm UTC
Feb 27, 2015 at 3:22pm UTC
Last edited on Feb 27, 2015 at 3:25pm UTC
Feb 27, 2015 at 5:26pm UTC
@Jaybob66
it's no working !
what's the libraries should I include ?
@rafae11
Thank you !
you code is well done !
but in the 2008 of MSVC it's no working .
Feb 28, 2015 at 1:04am UTC
it should work i use visual studio also. maybe you did not include "stdafx.h"