C++ 파일입출력 질문드립니다..

zmzm2260의 이미지

C++로 구현하는 과제를 하고있는데 다른건 c와 비슷해서 괜찮으나 파일입출력 토큰화하는 부분은 찾아봐도 잘 모르겠습니다..c++로 구현을 하라고 하셨지만 cstring의 strtok 함수를 사용해도 괜찮을까요?
100줄이 넘는 텍스트파일에서 " .,_\t"등의 토큰으로 단어를 분리해서 연결리스트에 넣는 건데 도통 작동하질 않습니다. 파일에서 여러줄을 입력받아서 토큰화하는 부분만 도와주시면 감사하겠습니다ㅠㅠ

세벌의 이미지

괜찮은지 아닌지는 과제 내주신 분에게 물어보셔야 할 듯.

joone의 이미지

https://www.geeksforgeeks.org/tokenizing-a-string-cpp/

// Tokenizing a string using stringstream 
#include <bits/stdc++.h> 

using namespace std; 

int main() 
{ 

    string line = "GeeksForGeeks is a must try"; 

    // Vector of string to save tokens 
    vector <string> tokens; 

    // stringstream class check1 
    stringstream check1(line); 

    string intermediate; 

    // Tokenizing w.r.t. space ' ' 
    while(getline(check1, intermediate, ' ')) 
    { 
        tokens.push_back(intermediate); 
    } 

    // Printing the token vector 
    for(int i = 0; i < tokens.size(); i++) 
        cout << tokens[i] << '\n'; 
}

참고하세요.