stringstream

2019-02-25  本文已影响0人  Hard模式

A stringstream associates a string object with a stream allowing you to read from the string as if it were a stream (like cin).

接口函数

clear() — to clear the stream
str() — to get and set string object whose content is present in stream.
operator << — add a string to the stringstream object.
operator >> — read something from the stringstream object,

应用

// A program to demonstrate the use of stringstream 
#include <iostream> 
#include <sstream> 
using namespace std; 
  
int main() 
{ 
    string s = "12345"; 
  
    // object from the class stringstream 
    stringstream geek(s); 
  
    // The object has the value 12345 and stream 
    // it to the integer x 
    int x = 0; 
    geek >> x; 
  
    // Now the variable x holds the value 12345 
    cout << "Value of x : " << x; 
  
    return 0; 
}
上一篇 下一篇

猜你喜欢

热点阅读