Input line by line from an input file and tokenize using strtok() and the output into an output file

前端 未结 2 1640
轻奢々
轻奢々 2020-12-14 03:41

What I am trying to do is to input a file LINE BY LINE and tokenize and output into an output file.What I have been able to do is input the first line in the file but my pro

2条回答
  •  暖寄归人
    2020-12-14 04:12

    The C++ String Toolkit Library (StrTk) has the following solution to your problem:

    #include 
    #include 
    #include 
    #include "strtk.hpp"
    
    int main()
    {
       std::deque word_list;
       strtk::for_each_line("data.txt",
                            [&word_list](const std::string& line)
                            {
                               const std::string delimiters = "\t\r\n ,,.;:'\""
                                                              "!@#$%^&*_-=+`~/\\"
                                                              "()[]{}<>";
                               strtk::parse(line,delimiters,word_list);
                            });
    
       std::cout << strtk::join(" ",word_list) << std::endl;
    
       return 0;
    }
    

    More examples can be found Here

提交回复
热议问题