error: no matching function for call to ‘std::vector<std:
error: no matching function for call to ‘std::vector<std:
我写 func 将字符串从文件写入向量并出现错误
error : error: no matching function for call to ‘std::vector<std::__cxx11::basic_string<char> >::push_back(std::ifstream&)
代码:
//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 ()
{
}
您正试图将 ifstream
推入向量,而不是从中读取。
要从 ifstream 读取,您可以执行以下操作。
void ReadFromFile (std::ifstream& thisin, std::vector<std::string>& thisData)
{
std::string word;
while(thisin >> word)
{
thisData.push_back(word);
}
}
我写 func 将字符串从文件写入向量并出现错误
error : error: no matching function for call to ‘std::vector<std::__cxx11::basic_string<char> >::push_back(std::ifstream&)
代码:
//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 ()
{
}
您正试图将 ifstream
推入向量,而不是从中读取。
要从 ifstream 读取,您可以执行以下操作。
void ReadFromFile (std::ifstream& thisin, std::vector<std::string>& thisData)
{
std::string word;
while(thisin >> word)
{
thisData.push_back(word);
}
}