Home > Enterprise >  moving data from a 2D vector to a variable --> E0349 no operator "=" matches these oper
moving data from a 2D vector to a variable --> E0349 no operator "=" matches these oper

Time:01-25

Literally just trying to move text data from a 2D vector to a variable.

I spent quite a bit of time searching google and SOF for this and I am shocked, there are hundreds of results but nothing this ...simple.

If this is a dup (and I am sure this is), if a mod could point me to it, I would be grateful.

#include <vector>
#include <string>

void main()
{
    std::string str_hi;
    std::string str_how;
    std::string str_goodbye;

    std::vector<std::vector<std::string>> vec_data
    {
        //    
            { "Hi", "" },
            { "How are you ?", "" },
            { "Good bye :)", "" }
    };

    str_hi = vec_data[0, 0]; // error here; red line under '='
    str_how = vec_data[1, 0]; // error here; red line under '='
    str_goodbye = vec_data[2, 0]; // error here; red line under '='
}```


> error: E0349 no operator "=" matches these operands
> error: E0349 no operator "=" matches these operands
> error: E0349 no operator "=" matches these operands
> 


CodePudding user response:

You need to change your syntax:

str_hi = vec_data[0][0];

Your version is using the comma operator. Look up "comma operator" in a good C text book. Also search the internet for "C FAQ Matrix".

  • Related