hilfe
-
ich komme nicht mehr weiter bin noch ein anfänger und weiss echt nicht mehr weiter ich bin schon so weit gekommen und will die ersten buchstaben von jedem Wort ausgeben kann mir da jemand helfen??
mein dokument sieht sehr mager aus aber soweit bin ich schon:#include <iostream>
#include <iomanip>
#include <conio.h>using namespace std;
int main()
{
cout<<" gateProtect AG ist eine Firma in Hamburg. Die Firmenadresse ist: „Valentinskamp 24, 20354 Hamburg“. ";
getch();
}
-
#include <iostream> #include <string> using namespace std; class Mojo { public: Mojo(string in):t(in),p(0){} bool operator++(){ switch(t[p]) { case' ':case'\t':case'„': if(++p<t.length()&&((t[p]>'a'&&t[p]<'z')||(t[p]>'A')&&(t[p]<'Z')))cout<<t[p]; break; default: p++; return end(); } return end(); } private: bool end(){return p<t.length();} string t; size_t p; }; int main() { Mojo mojo=" gateProtect AG ist eine Firma in Hamburg. Die Firmenadresse ist: „Valentinskamp 24, 20354 Hamburg“. "; while(++mojo); return 0; }
-
Man kann es aber auch verständlicher lösen :xmas1:
#include <iostream> #include <iomanip> #include <string> #include <conio.h> #include <ctype.h> using namespace std; int main() { string text = " gateProtect AG ist eine Firma in Hamburg. Die Firmenadresse ist: „Valentinskamp 24, 20354 Hamburg“. "; bool print_next_char = false; for ( const char* ptr=text.c_str(); *ptr!='\0'; ptr++ ) { if ( ! isalpha(*ptr) ) { print_next_char = true; } else if ( isalpha(*ptr) && print_next_char ) { cout << *ptr; print_next_char = false; } } getch(); }Ist nicht getestet und isalpha gibt zurück, ob das Zeichen ein Buchstabe, also ob
((c>='A' && c<='Z') || (c>='a' && c<='z'))wahr ist.