How can I read from memory just like from a file using iostream?

前端 未结 6 1028
醉话见心
醉话见心 2020-12-09 12:41

I have simple text file loaded into memory. I want to read from memory just like I would read from a disc like here:

ifstream file;
string line;

file.open(\         


        
6条回答
  •  遥遥无期
    2020-12-09 13:28

    You can use istringstream for that.

    string text = "text...";
    istringstream file(text);
    string line;
    
    while(file.good())
    {
        getline(file,line);         
    }
    

提交回复
热议问题