locked
How to traverse vector<string>? RRS feed

  • Question

  • I made a vector<string> like following

    vector<string> philosopher = { "Kant", "Plato", "Hume", "Kierkegaard" };
    for (string x:philosopher)	//for each x in v
        cout << x << endl;

    However compile error occur.

    Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
    
    How to make it work?

    Thursday, January 9, 2020 4:30 AM

All replies

  • You are missing   #include <string>

    Igor Tandetnik

    • Proposed as answer by Guido Franzke Thursday, January 9, 2020 8:13 AM
    Thursday, January 9, 2020 5:02 AM