vector - lvalue required as left operand of assignment error in c++ -


all of fellas, have problem code. try use macro , vector in code. but, there error in code, in macro code. dont know error. code :

#include <iostream> #include <vector> #include <string> #include <algorithm> #include <ostream>  using namespace std;  #define loop(a,b) for((int)(a) = 0; (a) < (int)(b); (a)++)  int main(){      vector<string> sentence;     sentence.reserve(10);      int i=0, c = sentence.size();      sentence.push_back("hello,");     sentence.push_back("how");     sentence.push_back("are");     sentence.push_back("you");     sentence.push_back("?");      loop(i,c){         cout << << endl;     }      return 0; } 

i hope of can me solve problem. regards.

it bad idea use such kind of macros in c++. problem expression

( int )( ) 

is rvalue (some temporary object) , may not assign value like

( int )( ) = 0; 

either remove entirely casting or @ least use casting ( int & ).

also when reserve memory vector using value greater current size of vector size not changed. so
in code snippet

vector<string> sentence; sentence.reserve(10);  int i=0, c = sentence.size(); 

c equal 0.

you should assign c after calling push_back.

int i=0;  sentence.push_back("hello,"); sentence.push_back("how"); sentence.push_back("are"); sentence.push_back("you"); sentence.push_back("?");  int c = sentence.size(); 

also not see relation between vector , loop. in opinion loop

loop(i,c){         cout << << endl; 

does not make sense. maybe mean output elements of vector you?

in case loop like

for ( const auto &s : sentence ) std::cout << s << std::endl; 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -