ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C++ 문자열 및 파일
    Programming 2016. 6. 7. 18:03

    std:string -> char*


    std::string str = "string";
    char* chr = str;

    chr = str.c_str();



    c++ getline함수


    1. <iostream>의 cin, <fstream>의 ifstream의 멤버 변수

    char cstr[512];cin.getline(cstr,512);

    ifstream inf("test.txt"); char cstr[512]; inf.getline(cstr,512);


    2. string의 getline함수
    string str1; 
    string str2; 
    ifstream inf("test.txt");
    getline(inf,str1); //파일 입출력 
    getline(cin,str2); //표준 입출력

    두가지 종류의  getline 이 있음. 

    istream& getline (istream& is, string& str, char delim);

    istream& getline (istream& is, string& str);



    comma로 문자열 split하기

    stringstream ss( "1,1,1,1, or something else ,1,1,1,0" );
    vector<string> result;
    
    while( ss.good() )
    {
        string substr;
        getline( ss, substr, ',' );
        result.push_back( substr );
    }

    getline함수에서 ','가 delimiter역할을 하여, comma로 문자열 split이 가능. 

    http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring



    file관련 c++ class

    reference : http://www.cplusplus.com/reference/istream/iostream/

    istream(input)

    iostream: fstream, stringstream

    ifstream

    istringstream

    ostream(output)

    iostream: fstream, stringstream

    ofstream

    ostringstream


    'Programming' 카테고리의 다른 글

    fsharp compiler, interpreter 작업환경  (0) 2017.04.21
    python 코딩  (0) 2017.01.31
    sourceforces 158B - 10  (0) 2016.05.19
    making fuzzer w/ eclipse pydev  (0) 2016.04.09
    Scope Table  (0) 2015.06.26
Designed by Tistory.