0

このエラーの原因となっているスクリプトの何が間違っているのか、少し混乱しています。

ゲーム設定のフィルを呼び出す関数がありますが、getline が気に入りません。

また、これらは私がそれに含めたファイルです:

#include <fstream>
#include <cctype>
#include <map>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;'

これは私が持っているものです:

std::map<string, string> loadSettings(std::string file){

ifstream file(file);
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);
}

関数は私のからこのように呼び出されますmain.cpp

 //load settings for game
 std::map<string, string> config = loadSettings("settings.txt");
 //load theme for game
 std::map<string, string> theme = loadSettings("theme.txt");

どこで私は間違えましたか ?助けてください!

エラー:

settings.h(61): 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 'std::basic_istream<_Elem,_Traits> &&' from 'std::string'

4

1 に答える 1

1
std::map<string, string> loadSettings(std::string file){
    std::ifstream file(file);

ファイルは astd::stringおよび aに対して定義されてstd::ifstreamいます。別の名前を付けてください。

エラーは、 ;を期待する関数std::stringの最初のパラメーターに を一致させることができないことを示しています。std::getlinestd::basic_istream<E,T>

編集: また、std::接頭辞を付けて一貫性を保つ必要があります。文字列と ifstream は両方とも名前空間にありますstd::

于 2012-11-07T22:56:54.943 に答える