// ************************************************ // STRINGS - conversoes // // ************************************************ #include #include using namespace std; using std::cout; using std::endl; using std::string; #include using std::stringstream; int main() { string s1, s2; char Old[50]; float f = 123.4; // conversão usando "sprintf" sprintf(Old, "%f", f); s1 = Old; cout << "Saida:" << s1 << endl; // conversão usando "stringstream" stringstream buffer; f = 678.23; buffer << f << "***"; s1 = buffer.str(); cout << "Saida:" << s1 << endl; stringstream aux; aux << "1213.987"; aux >> f; cout << "Saida(float):" << f << endl; system("PAUSE"); return 0; }