Chiusakpung's Electronics Blog

블로그 이미지
Computer programming ...
by 치우삭풍
  • Total hit
  • Today hit
  • Yesterday hit

'ostringstream'에 해당되는 글 1건

  1. 2010.10.02
    How to clear ostringstream
The class ostringstream is often used for combining many number chains and transforming it into string, such as itoa() or sprintf( ... , "%f" , ...) in C standard library

The following is an example of this class.

int main() {
     ostringstream myO;
     myO << 12 << 8; // myO = "128"
     cout << myO.str() << endl;
     return 0;
}

Result>
128

To clear myO up, use myO.str("")

Wait! if you want to use the string contained in myO instance at the time of calling the constructor of ifstream instance, for example,  ifstream inf (myO.str()), we cannot miss a serious (and terrible) mass of compile message. To avoid it, we need one more method c_str().

ifstream inf (myO.str().c_str())
AND

ARTICLE CATEGORY

전체 (126)
EECS (56)
Physics (5)
Misc. (60)

RECENT ARTICLE

RECENT COMMENT

RECENT TRACKBACK

CALENDAR

«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

ARCHIVE