c++ - How to modify a vector member's value? -
I was trying to use vector svec to store some string values. But when compiling in Dev C ++ 5.6.1, the compiler reported an error of "No match for operator =". Why is this error and how to fix it? Thank you.
contains # lt; Vector & gt; # Include & lt; Iostream & gt; #include & lt; string & gt; using namespace std; Int main () {Vector & lt; String & gt; Swek [100]; {Svec [i] = "ABC" for (int i = 0; i & lt; 100; ++ i); } Return 0; } [Error] There is no match for 'operator =' (Operating Type 'std :: vector>' and 'const char [4]') Edit: Problem vector is in svec [100 ]; By changing it vector svec (100);
edit2: I'm curious that the compiler is concerned about this low declaration. Is svec still declared as a vector?
vector & lt; String & gt; Swek [100];
vector & lt; String & gt; Svec [100];
std :: vector & lt; Std :: string & gt; Creating an array with 100 elements of
This is a valid syntax, though it is a strange thing to do.
In its current form, svec [i]
hence the std :: vector & lt; Std :: string & gt;
. It is not possible to assign "ABC" to the reason that you get an error.
What do you mean by writing vector & lt; String & gt; Swake (100);
. It is calling one of the vector
constructor which is 100 elements in the pre-shaped vector.
It just happens that std :: vector
overloads the code to access the code <> operator (for pure array Convenient corresponds.) If you make changes, then svec [i]
will mention a string that you can currently do.
Comments
Post a Comment