Tuesday, October 27, 2009

C++ convert anything to anything

Usually conversion of int to string involves some complex loops in c++, however there is actually a simple buffer class that we can use to simplify the conversion for us. Moreover it actually can convert any primitive data type to any primitive data type. by primitive meaning int, char, double, float, string... though string is not to consider primitive..(ntah?). It can be done by few line of code below :

#include
#include
using namespace std;

int main(){
stringstream buffer;

string Astring = "1234";
double Adouble;
int Aint = 32;

buffer<<>Adouble;

cout<>Adouble , we give the buffer a place to store in variable of data type double, since Adouble is a double data type..stringstream can receive any primitive , then rebuffer it to any primitive..

Awat 65.82.89 ?

Salam.. baru je wat blog... tp xrasa nak wat pasal diary.. ak wat sbb nak share2 ilmu je.. awat 65.82.89? sbb dlm asci code char maksud die A.R.Y.. :D..