我使用map来存储从文本文件解析的数据。实际的代码是相当庞大的,虽然我可以发布它,如果这还不够,但这里是对导致问题的行的任何贡献的大纲:
#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
}这会导致此编译错误:
error C2664: 'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> &)' :
cannot convert argument 1 from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> '
to 'const std::string &'我怀疑我在“字符串”主题上使用了C++的数百万个变体中的错误一个,但是我不确定,如果是这样的话,我不知道我应该使用什么或者如何修复它。
发布于 2014-05-21 04:51:49
这句话
map<string,string> currentBlock(map<string,string>());是一个函数声明,它具有返回类型映射和一个函数类型的参数,该参数也具有相同的返回类型。。
很明显,这个结构
map<string,string>()是一个函数声明,其中抽象声明符作为函数.currentBlock的参数。
写得简单
map<string,string> currentBlock;同样的道理也适用于行
string keyS(string(key));
string entryS(string(entry));也就是说,它们也是具有名称、键和std::string类型条目的参数的函数声明
https://stackoverflow.com/questions/23769636
复制相似问题