编译下面的代码时出错 错误(有效)E0349无操作员“<<”或“>>”匹配这些操作数并强调cout<<和cin>>码。不确定是什么导致它。已包含标题#include。我将不胜感激任何帮助修复此错误或建议可能的原因。
#include <iostream>
#include <vector>
using namespace std;
void SSort(vector<string>& input) {
int n = input.size();
for (int i = 0; i < n - 1; i++) {
int min_idx = i;
for (int j = i + 1; j < n; j++)
if (input[j] < input[min_idx])
min_idx = j;
string t = input[min_idx];
input[min_idx] = input[i];
input[i] = t;
}
}
int BS(vector<string> input, string x) {
int left = 0, right = input.size() - 1;
while (left <= right) {
int m = left + (right - left) / 2;
if (input[m] == x)
return m;
if (input[m] < x)
left = m + 1;
else
right = m - 1;
}
return -1;
}
void print(vector<string> input) {
for (int i = 0; i < input.size(); i++)
cout << input[i] << endl;
}
int main()
{
vector<string> input;
input.push_back("welcome");
input.push_back("to");
input.push_back("coding");
input.push_back("test");
input.push_back("selection");
input.push_back("sort");
input.push_back("using");
input.push_back("binary");
input.push_back("search");
SSort(input);
cout << "Sorted Vector: \n";
print(input);
while (true) {
string key;
cout << "Enter key to search: (press Q to exit)";
cin >> key;
if (key == "Q") {
break;
}
int index = BS(input, key);
if (index == -1)
cout << key << " not in vector" << endl;
else
cout << key << " is at " << index << " in vector" << endl;
}
return 0;
}