小编Wat*_*ave的帖子

std :: map <,>.emplace()产生错误

我正在使用地图来存储从文本文件解析的数据.实际的代码非常大,虽然如果这还不够,我可以发布它,但是这里有导致问题的那一行的大纲:

#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

}
Run Code Online (Sandbox Code Playgroud)

这会导致此编译错误:

error C2664: 'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> …
Run Code Online (Sandbox Code Playgroud)

c++ string c++11

1
推荐指数
1
解决办法
363
查看次数

使用错误数量的元素初始化的C++ char数组

当我使用指针初始化cstring时,如下所示:

char* title = new char[endTitleChar - startTitleChar + 1];
Run Code Online (Sandbox Code Playgroud)

...它初始化为char [24],无论方括号中表达式的实际值如何,都是从12到1的任何值.

这里发生了什么事?

c++ visual-studio-2013

1
推荐指数
1
解决办法
266
查看次数

标签 统计

c++ ×2

c++11 ×1

string ×1

visual-studio-2013 ×1