C++错误,编译器将无法识别字符串::p ush_back
C++ error, compiler won't recognize string::push_back
它具有以下问题的功能:
string encode (string message, string key) {
string code = "whatever";
string forst;
int num;
string::size_type begin = 0;
message = lower_and_strip(message);
for (char val : message) {
num = return_encoded_char(key, begin, val);
forst = to_string(num);
code.push_back(forst); //*******************************
}
return code;
}
星系是指的。return_encoded_char函数返回整数。
具体错误是 proj05.cpp:68:23: error: no matching function for call to 'std::basic_string<char>::push_back(std::string&)'
并指向我出演的线。
我最初只是在没有初始化的情况下声明了code
,但是更改它没有修复它。我发现的所有类似问题还需要归咎于其他元素。我觉得这应该相对简单,尽管显然不是因为它不起作用。
我有#include <stream>
和using std::to_string
等。我正在使用-std = C 11来编译它。
帮助。
P.S。在Linux上使用Geany。
您的code
变量是std::string
。std::string
类没有push_back()
方法,该方法将另一个std::string
作为输入。您应该使用+=
操作员尝试,该操作员接受字符或字符串:
string encode (string message, string key) {
string code = "whatever";
string forst;
int num;
string::size_type begin = 0;
message = lower_and_strip(message);
for (char val : message) {
num = return_encoded_char(key, begin, val);
forst = to_string(num);
code += forst; //*******************************
}
return code;
}