0

I write func to write strings from file to vector and have a error

error : error: no matching function for call to ‘std::vector<std::__cxx11::basic_string<char> >::push_back(std::ifstream&)

code:

//parse file file

#include <fstream>
#include <vector>

const unsigned short numOfStrings=5;

void ReadFromFile (std::ifstream& thisin, std::vector<std::string>& thisData)
{
    thisData.push_back(thisin);
}

int main ()
{
}
east1000
  • 1,240
  • 1
  • 10
  • 30

1 Answers1

1

You are trying to push into the vector the ifstream, not reading from it.

To read from ifstream, you could have done the following.

void ReadFromFile (std::ifstream& thisin, std::vector<std::string>& thisData)
{
    std::string word;
    while(thisin >> word)
    {
        thisData.push_back(word);
    } 
}
Karen Baghdasaryan
  • 2,407
  • 6
  • 24