w 4A zastosowałbym find if. a nastepnie erase na danym elemencie stringa ale cos mi tu nie dziala....
No tak, bo błędów tutaj sporo (w komentarzach)
#include <iostream>
#include <algorithm>
using namespace std;
bool isEven( char x)
{
return islower(x); // islower jest w <cctype> który nie jest dołączony
}
int main()
{
string word = "teSt";
int * it = find_if( word.begin(),word.end(), isEven );
// po pierwsze, int * it? Nic z algorytmów nie zwraca wskaźników, o to chodzi w iteratorach
// po drugie, czemu find_if?
// http://www.cplusplus.com/reference/algorithm/find_if/
// Returns an iterator to the first element in the range [first,last) for which pred returns true. If no such element is found, the function returns last.
// Chyba tego jednak nie przemyślałeś (albo wybraleś losową funkcję?). W każdym razie, Tobie chodzi o remove_if
// http://www.cplusplus.com/reference/algorithm/remove_if/
cout<<*it ; // no i ostatnia rzecz, co to ma zrobić?
// 1) Rzeczy z algorithm jeśli coś zwracają, to jest to często np. iterator do ostatniego elementu (find do znalezionego elementu albo końca).
// 2) Nie możesz tak wypisać iteratora (tzn. jeśli to miało wypisać tekst po usunięciu niedużych liter, bo pojedynczy element jak najbardziej można tak wyświetlić
}
To moja propozycja rozwiązania:
#include <iostream>
#include <cctype>
#include <algorithm>
using namespace std;
bool isNotUpper(char x){ return !isupper(x); }
int main()
{
string word = "teStAsRsa";
string::iterator begin = word.begin(), end = word.end();
end = remove_if(begin, end, isNotUpper);
for (string::iterator it = begin; it != end; it++) {
cout << *it;
} cout << endl;
}