0

Getting errors when compiling the below code that say Error (active)E0349 no operator "<<" or ">>" matches these operands and are underlining the cout << and cin >> code. Not sure what is causing it. Have included the header #include. I would appreciate any help in fixing this error or suggestions on what might be the cause.

#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;
}
  • 3
    [Cannot Reproduce](https://repl.it/repls/DarkgreenKeyBackslash) – Arnav Borborah Feb 15 '18 at 02:46
  • 3
    The operators for `std::string` is in the `` header. Add another `#include`. – Bo Persson Feb 15 '18 at 02:49
  • Your right Bo Persson, that fixed the issue.. Thanks, I tried looking online but keep getting references. Arnav Borborah I had the same thing happen origninally. Worked fine on the online program my class is using but the minute I dropped into Visual Studios it started complaining. Thanks for clarifying that the problem was with the compiler user4581301. They never bother to warn you about stuff like that in the classroom setting :( – Kristina Woods Feb 15 '18 at 03:00
  • 1
    `string` may or may not be included by `iostream`. In @ArnavBorborah 's case (g++ compiler) it is. In the Asker's case (Visual Studio) it isn't. To avoid nasty surprises like this always include the headers for all of the functionality you use. – user4581301 Feb 15 '18 at 03:00

0 Answers0