8.3(금) C++ - stringstream

from Study/C++ 2007/08/08 11:49 view 21058

#include <sstream>

#include <fstream>

 

// stringstream 에 대해서

// stream3개로 구분 할 수 있다. istream, ostream, stringstream

 

void main()

{

        char buf [256];

        cin >> buf;    // 표준입력에서 입력

 

        ifstream f("a.txt");

        f >> buf;      // 화일에서 입력

 

        //////////////////////////////////////////////////////

        string s = "I am a boy";

        istringstream iss(s);

 

        // 하나의 문장을 단어별로 분리하는 기법

        while( iss >> buf )

        {

               cout << buf << endl;

        }

}

//////////////////////////////////////////////////////
void
main()

{

        ofstream f("a.txt");

        ostringstream oss;

 

        cout << "A";   // 표준출력으로 출력

        f       << "A";       // 화일로 출력(a.txt 파일)

        oss     << "A";

 

        string s = oss.str();  // oss 가 내부적으로 가진 string 꺼낸다.

        cout << s << endl;

}

Tag |

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다