fork download
  1. #include<iostream>
  2. #include<cstring>
  3. #include<string>
  4. using namespace std;
  5.  
  6. bool isLonger(string first, string second)
  7. {
  8. return first.size() > second.size();
  9. }
  10.  
  11. int main()
  12. {
  13. cout << "\tErste Schritte mit String\n\n";
  14. cout << "\n";
  15. int number_1;
  16.  
  17. do
  18. {
  19. cout << "Was wollen Sie tun?\n";
  20. cout << "(1) Texte miteinander vergleichen\n";
  21. cout << "(2) Passwortabfrage\n";
  22. cout << "(3) Nach Buchstaben in einem Text suchen\n";
  23. cout << "(0) Exit\n";
  24. cin >> number_1;
  25.  
  26. switch(number_1)
  27. {
  28. case 1:
  29. string erste;
  30. cin >> erste;
  31. string zweite;
  32. cin >> zweite;
  33. if(isLonger(erste,zweite))
  34. cout << "Der erste ist länger";
  35. else
  36. cout << "Der zweite ist länger";
  37. break;
  38. case 2:
  39. std::cin.ignore(1);
  40. string e;
  41. e = "Maximilian*Maximilian";
  42.  
  43. cout << "\n";
  44. cout << "\tPasswortabfrage!\n";
  45. cout << "\n";
  46.  
  47. do
  48. {
  49. cout << "Wie lautet das Passwort?\n";
  50. cin >> e;
  51. if(e=="Maximilian*Maximilian")
  52. cout << "Richtig eingegeben";
  53. else
  54. cout << "Nicht richtig eingegeben!\n";
  55. }while(e!="Maximilian*Maximilian");
  56. break;
  57. case 3:
  58. std::cin.ignore(2);
  59. char String[10000];
  60. char *pString;
  61. char Buchstabe;
  62.  
  63. cout << "Geben Sie einen String von weniger als 10000 Buchstaben ein!\n";
  64. gets(String);
  65.  
  66. cout << "Nach welchem Buchstaben soll gesucht werden?\n ";
  67. cin >> Buchstabe;
  68.  
  69. pString = strchr(String, Buchstabe);
  70.  
  71. while(pString!=NULL)
  72. {
  73. cout << "Gefunden an " << pString-String+1 << "\n";
  74. pString = strchr(pString+1, Buchstabe);
  75. }
  76. break;
  77. case 0:
  78. cout << "Exit durch Abbruch!\n";
  79. break;
  80. }
  81. }while(number_1!=0);
  82.  
  83. return 0;
  84. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:38:18: error: jump to case label
prog.cpp:31:24: error:   crosses initialization of 'std::string zweite'
prog.cpp:29:24: error:   crosses initialization of 'std::string erste'
prog.cpp:57:18: error: jump to case label
prog.cpp:40:24: error:   crosses initialization of 'std::string e'
prog.cpp:31:24: error:   crosses initialization of 'std::string zweite'
prog.cpp:29:24: error:   crosses initialization of 'std::string erste'
prog.cpp:77:18: error: jump to case label
prog.cpp:40:24: error:   crosses initialization of 'std::string e'
prog.cpp:31:24: error:   crosses initialization of 'std::string zweite'
prog.cpp:29:24: error:   crosses initialization of 'std::string erste'
stdout
Standard output is empty