小编awe*_*007的帖子

矢量push_back返回无效转换

我是 cpp 矢量新手,我一直遇到这个问题

\n

error: no matching function for call to \xe2\x80\x98push_back(const char [6])\xe2\x80\x99

\n
#include <vector>\n#include <iostream>\nusing namespace std;\nint main() {\n    vector<int> names;\n    names.push_back("Lewis");\n    names.push_back("Mark");\n    names.push_back("Reece");\n    names.push_back("Max");\n    for(int i = 0; i < names.size(); i++)\n        cout << names[i] << \'\\n\';\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是错误

\n
test.cpp: In function \xe2\x80\x98int main()\xe2\x80\x99:\ntest.cpp:6:26: error: no matching function for call to \xe2\x80\x98push_back(const char [6])\xe2\x80\x99\n    6 |   names.push_back("Lewis");\n      |                          ^\nIn file included from /usr/include/c++/9/vector:67,\n                 from test.cpp:1:\n/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: \xe2\x80\x98void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp …
Run Code Online (Sandbox Code Playgroud)

c++ vector c++11

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

标签 统计

c++ ×1

c++11 ×1

vector ×1