C++ 标准::映射<>;。emplace()生成错误

C++ 标准::映射<>;。emplace()生成错误,c++,string,c++11,C++,String,C++11,我正在使用映射来存储从文本文件解析的数据。实际的代码相当丰富,虽然如果这还不够的话,我可以发布它,但下面是导致问题的代码的概要: #include <stdio.h> #include <iostream> #include <fstream> #include <SDL.h> #include <map> using namespace std; bool processTXT(char path[]) { ifstrea

我正在使用映射来存储从文本文件解析的数据。实际的代码相当丰富,虽然如果这还不够的话,我可以发布它,但下面是导致问题的代码的概要:

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <SDL.h>
#include <map>

using namespace std;

bool processTXT(char path[])
{
    ifstream source;
    source.open(path);

    char* key = new char[200];
    char* entry = new char[200];

    ifstream.getline(key, 200);
    ifstream.getline(entry, 200);

    //Not quite the original, but close enough; add lots of processing here

    map<string,string> currentBlock(map<string,string>());

    string keyS(string(key));
    string entryS(string(entry));
    currentBlock.emplace(keyS, entryS); //<----- THIS line seems to be the problem

    //Serialisation (of currentBlock) that I have yet to implement

}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
bool processTXT(字符路径[])
{
流源;
开源(路径);
字符*键=新字符[200];
char*entry=新字符[200];
ifstream.getline(键,200);
ifstream.getline(条目,200);
//不完全是原始的,但足够接近;在这里添加大量处理
映射当前块(map());
字符串键(字符串(键));
字符串入口(字符串(条目));
currentBlock.emplace(键、入口);//此语句

map<string,string> currentBlock(map<string,string>());
也就是说,它们也是函数声明,其参数名为key,条目类型为std::string

map<string,string> currentBlock(map<string,string>());


也就是说,它们也是函数声明,其中的参数名为key,条目类型为std::string

它是否与
currentBlock.emplace(std::make_pair(key,entryS))一起工作
?甄说了什么,而且你也不需要像那样初始化映射。映射currentBlock;
就足够了。@甄,你需要
currentBlock.emplace(std::make_pair(keyS,entryS));
你有很多双重构造。或者你认为:)它与
currentBlock.emplace一起工作吗(std::make_pair(key,entryS));
?甄说了什么,而且你也不需要像那样初始化映射。一个
映射currentBlock;
就足够了。@Zhen,你想要
currentBlock.emplace(std::make_pair(key,entryS));
你有很多双重构造在进行。或者你认为你是:)对于
入口
,您想用额外的括号将它们包围起来(或者只使用
字符串键(键)
,请参阅下面的@LightnessRacesinOrbit注释)@vsoftco我也发现了这一点。@Zhen这太傻了。
字符串键(键)
没有重复的类型。@Zhen是赫伯·萨特(Herb Sutter)少有的不那么棒的想法之一。@Zhen:听到这个消息我很难过。对于
键和
入口,同样的,你想用额外的括号将它们括起来(或者只使用
字符串键(键)
,请参阅下面的@Lightness RaceSinorbit评论)@vsoftco我也发现了这一点。@Zhen这太傻了。
string key(key)
没有重复的类型。@Zhen是赫伯·萨特(Herb Sutter)罕见的不那么棒的想法之一。@Zhen:听到这个消息我很难过。
map<string,string>()
map<string,string> currentBlock;
string keyS(string(key));
string entryS(string(entry));