H
hugo_ribeira
Hello guys,
this is my code:
"
// CHAPTER 14
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "mine.h"
using namespace std;
int x[] = {1,2,1,4,3,2,1,4,5,6,7,8,1,3,1,3};
vector<int> y(x, x + sizeof(x)/sizeof(int));
class equals
{
int _test_case;
public:
equals(int test_case): _test_case(test_case) {}
bool operator()(int var)
{
return _test_case == var;
}
};
int main()
{
for(auto i = y.begin(); i < y.end(); ++i)
cout << *i;
cout << endl << endl;
remove_if(y.begin(), y.end(), equals(1));
for(auto i = y.begin(); i < y.end(); ++i)
cout << *i;
keepopen();
return EXIT_SUCCESS;
}
"
It's suposed to remove all the 1's from y, but it isn't. This is the
output:
1214321456781313
2432456783381313
^ ^
Those 1's were not suposed to be there, or were they?
this is my code:
"
// CHAPTER 14
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "mine.h"
using namespace std;
int x[] = {1,2,1,4,3,2,1,4,5,6,7,8,1,3,1,3};
vector<int> y(x, x + sizeof(x)/sizeof(int));
class equals
{
int _test_case;
public:
equals(int test_case): _test_case(test_case) {}
bool operator()(int var)
{
return _test_case == var;
}
};
int main()
{
for(auto i = y.begin(); i < y.end(); ++i)
cout << *i;
cout << endl << endl;
remove_if(y.begin(), y.end(), equals(1));
for(auto i = y.begin(); i < y.end(); ++i)
cout << *i;
keepopen();
return EXIT_SUCCESS;
}
"
It's suposed to remove all the 1's from y, but it isn't. This is the
output:
1214321456781313
2432456783381313
^ ^
Those 1's were not suposed to be there, or were they?