This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
cpp:stringstreams [2019/05/20 09:14] gthanos |
cpp:stringstreams [2019/05/21 19:49] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== String streams ====== | ||
| - | Εκτός από τις κλάσεις για ανάγνωση ή εγγραφή από αρχείο ή τα //stdin// και //stdout// η // | ||
| - | |||
| - | * **istringstream: | ||
| - | * **ostringstream: | ||
| - | * **stringstream: | ||
| - | |||
| - | <code cpp stringstream.cpp> | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | using namespace std; | ||
| - | int main() { | ||
| - | stringstream sstream; | ||
| - | | ||
| - | sstream << " | ||
| - | string token; | ||
| - | while( sstream >> token ) { | ||
| - | cout << token << " "; | ||
| - | } | ||
| - | cout << endl; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Μετατροπή αριθμών σε strings και αντίστροφα ===== | ||
| - | |||
| - | Μπορούμε να χρησιμοποιήσουμε ένα // | ||
| - | |||
| - | <code cpp stringstream.cpp> | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | using namespace std; | ||
| - | |||
| - | int main() { | ||
| - | string expr; | ||
| - | cout << "Enter arithmetic expression: "; | ||
| - | cin >> expr; | ||
| - | istringstream stream(expr); | ||
| - | | ||
| - | } | ||
| - | </ | ||