【发布时间】:2020-12-03 06:02:28
【问题描述】:
我已插入一个字符串,我希望将每个字符分别插入向量字符串中。在使用 push_back 函数时,我收到以下错误:
错误:没有匹配的函数调用
'std::vector<std::__cxx11::basic_string<char> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)' 27 | color.push_back(str[i]);**
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int t;
cin >> t;
string str;
char in;
while(t--){
cin >> str;
sort(str.begin(), str.end());
vector<string> chr;
for (int i = 0; i < str.size(); i++){
chr.push_back(str[i]);
}
for (int i = 0; i < chr.size(); i++)
cout << chr[i] << " ";
}
}
非常感谢您
【问题讨论】:
-
你真的想要一个字符串向量吗?听起来你想要一个字符向量
std::vector<char> -
Push_back 函数需要一个字符串而不是字符,str[i] 是一个字符而不是字符串
标签: c++ string vector stl push-back