devxlogo

Reading a String from a File

Reading a String from a File

classes overload the operators >> for reading from a file and #include #include using namespace std;int main(){ ifstream ftext; string word; vector vs; ftext.open("data.txt"); if (!ftext) exit (-1); while (ftext>>word) // as long as sizeof hasn't been reached { vs.push_back(word); //copy word to vector }}

devx-admin

Share the Post: