我有一个 cpp 文件,它可以抓取线条并修剪它们,但我遇到了错误。
错误说:
error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
我不确定这意味着什么......但这是脚本......:
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <cctype>
#include "settings.h"
using namespace std;
// trim from start
static inline std::string& line_trim(std::string& s) {
//erase
s.erase(
//pointer start location
s.begin(),
//find from pointer which is set to begin
std::find_if( s.begin(),
//check to the end
s.end(),
//look for spaces
std::not1( std::ptr_fun<int, int>(std::isspace) ) ) );
//return the result
return s;
}
// trim from end
static inline std::string& end_trim(std::string& s) {
//erase
s.erase(
//find from the pointer set to end of line
std::find_if(s.rbegin(),
//check to the beginning (because were starting from end of line
s.rend(),
//look for spaces
std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
s.end());
return s;
}
static inline std::string& trim(std::string &s) {
return line_trim(end_trim(s));
}
ifstream file(std::string file_path){
string line;
std::map<string, string> config;
while(std::getline(file, line))
{
int pos = line.find('=');
if(pos != string::npos)
{
string key = line.substr(0, pos);
string value = line.substr(pos + 1);
config[trim(key)] = trim(value);
}
}
return (config);
}
该错误发生在第三个函数中,例如:
while(std::getline(file, line))
编辑:这是我的settings.h
#include <map>
using namespace std;
static inline std::string &line_trim(std::string&);
static inline std::string &end_trim(std::string&);
static inline std::string &trim(std::string&);
std::map<string, string> loadSettings(std::string);
任何想法我做错了什么?