if i compile my following code in code blocks it compiles perfectly but when i try it in eclipse it shows a lot of errors. Can someone tell me what can i do?
my code is as follows****
#include<iostream>
#include<cstdlib>
#include <algorithm>
#include<ctime>
#include<iomanip>
#include<vector>
using namespace std;
int myrandom (int i) { return std::rand()%i;}
int card_to_move(vector<string> input) // function to check if the players has the same suit
{
int i =0; int j;
char suit = input.at(0).at(0);
for (auto comparison : input)
{
if (comparison.at(0) == suit){
i++;
}
else{j=i;break;}
}return j;
}
bool are_all_same_suit(vector<string> input)// function to compare suits
{
char suit = input.at(0).at(0);
for (auto comparison : input)
{
if (comparison.at(0) != suit) return false;
}
return true;
}
int main()
{
// set some values:
for (int i=1; i<52; ++i) myvector.push_back(cards[i]);
// using built-in random generator:
random_shuffle ( myvector.begin(), myvector.end() );
// using myrandom:
random_shuffle ( myvector.begin(), myvector.end(), myrandom);// shuffling so that a cards is not generated twice
for (std::vector<string>::iterator it=myvector.begin(); it!=myvector.end(); ++it){
//std::cout << ' ' << *it;
all_cards.push_back(*it);}//all cards saved at all_cards
for(int i=0;i<7;i++){
player_0.push_back(all_cards[i]);
player_1.push_back(all_cards[i+9]);
player_2.push_back(all_cards[i+18]);
player_3.push_back(all_cards[i+27]);
player_4.push_back(all_cards[i+36]);
}
string x,a,b,c,d,e,f,g,y;
a=player_0[0];b=player_0[1];c=player_0[2];d=player_0[3];e=player_0[4];f=player_0[5];g=player_0[6];
cout<<"player_0 (a)"<<a<<setw(5)<<"(b)"<<b<<setw(5)<<"(c)"<<c<<setw(5)<<"(d)"<<d<<setw(5)<<"(e)"<<e<<setw(5)<<"(f)"<<f<<setw(5)<<"(g)"<<g<<endl;
char choice; // player_0' choice
cout << "which one to replace ?"<<endl;
while(cin >> choice)
{
cout << "which one to replace ?"<<endl;
char check;
switch (choice){ // switch the option the player is choosing
case 'a':
player_1.push_back(player_0[0]);
player_0.erase(player_0.begin());
break;
case 'b':
player_1.push_back(player_0[1]);
player_0.erase(player_0.begin()+1);
break;
case 'c':
player_1.push_back(player_0[2]);
player_0.erase(player_0.begin()+2);
break;
case 'd':
player_1.push_back(player_0[3]);
player_0.erase(player_0.begin()+3);
break;
case 'e':
player_1.push_back(player_0[4]);
player_0.erase(player_0.begin()+4);
break;
case 'f':
player_1.push_back(player_0[5]);
player_0.erase(player_0.begin()+5);
break;
case 'g':
player_1.push_back(g);
player_0.erase(player_0.begin()+6);
break;
case '?':
cout<<"player_0 (a)"<<a<<setw(5)<<"(b)"<<b<<setw(5)<<"(c)"<<c<<setw(5)<<"(d)"<<d<<setw(5)<<"(e)"<<e<<setw(5)<<"(f)"<<f<<setw(5)<<"(g)"<<g<<endl;
cout<<"player_1 (a)"<<player_1[0]<<setw(5)<<"(b)"<<player_1[1]<<setw(5)<<"(c)"<<player_1[2]<<setw(5)<<"(d)"<<player_1[3]<<setw(5)<<"(e)"<<player_1[4]<<setw(5)<<"(f)"<<player_1[5]<<setw(5)<<"(g)"<<player_1[6]<<endl;
cout<<"player_2 (a)"<<player_2[0]<<setw(5)<<"(b)"<<player_2[1]<<setw(5)<<"(c)"<<player_2[2]<<setw(5)<<"(d)"<<player_2[3]<<setw(5)<<"(e)"<<player_2[4]<<setw(5)<<"(f)"<<player_2[5]<<setw(5)<<"(g)"<<player_2[6]<<endl;
cout<<"player_3 (a)"<<player_3[0]<<setw(5)<<"(b)"<<player_3[1]<<setw(5)<<"(c)"<<player_3[2]<<setw(5)<<"(d)"<<player_3[3]<<setw(5)<<"(e)"<<player_3[4]<<setw(5)<<"(f)"<<player_3[5]<<setw(5)<<"(g)"<<player_3[6]<<endl;
cout<<"player_4 (a)"<<player_4[0]<<setw(5)<<"(b)"<<player_4[1]<<setw(5)<<"(c)"<<player_4[2]<<setw(5)<<"(d)"<<player_4[3]<<setw(5)<<"(e)"<<player_4[4]<<setw(5)<<"(f)"<<player_4[5]<<setw(5)<<"(g)"<<player_4[6]<<endl;
cout << endl;
cout << "which one to replace ?"<<endl;
break;
default:
break;
}
// checking if the player has the same suit of cards
if(are_all_same_suit(player_0)==true){
cout<<"player_0 wins"<<endl;
break;
}
else if(are_all_same_suit(player_1)==true){
cout<<"player_1 wins" <<endl;
break;
}
else if(are_all_same_suit(player_2)==true){
cout<<"player_2 wins" <<endl;
break;
}
else if(are_all_same_suit(player_3)==true){
cout<<"player_3 wins" <<endl;
break;
}
else if(are_all_same_suit(player_4)==true){
cout<<"player_4 wins" <<endl;
break;
}
else{ // if the player has mismatch cards they choose to obtain different cards
if(choice=='?'){continue;}
if(are_all_same_suit(player_1)!=true){
player_2.push_back(player_1[card_to_move(player_1)]);
player_1.erase(player_1.begin()+(card_to_move(player_1)));}
if(are_all_same_suit(player_2)!=true){
player_3.push_back(player_2[card_to_move(player_2)]);
player_2.erase(player_2.begin()+(card_to_move(player_2)));
When you get a bunch of error like this you should always start at the top. Often later errors will just go away when you remove an earlier error.
The first warning and the first error talks about this line.
for (auto comparison : input)
This line of code uses two new features that was added C++ in C++11 (the 2011 version of the C++ standard).
* automatic type detection
* range-based for loops
If you want to use C++11 features you need to pass the compiler flag -std=c++11 to g++.
This is probably the reason why you had different results from one IDE to another, the default warning level was different. Some IDE's have no default complier warning options at all, not even -Wall - which is crazy IMO.