If statment crashing.

Why is this "if " statment crashing. I get Konsole.exe has stoped working
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;


int main()
 {
     string mystr;
     //Config
     system("color F0");
     system("title HK-Konsole");
     //Starting console
     std::cout << "Starting HK-Konsole 1.0...\n\n";
     Sleep(1806);
     std::cout << " ##############################################################################\n";
     std::cout << " #                                                                            #\n";
     std::cout << " #                                 HK-Konsole                                 #\n";
     std::cout << " #                                                                            #\n";
     std::cout << " ##############################################################################\n";
     //The console
     while (true) {
     std::cout << ("C:/Konsole/Commands/>");
     std::string(mystr);
     scanf("%s", &mystr);
     if (mystr == "cls")
     {
        system("cls");
     }
     }
 }


You ignored what I pointed out in your other thread.
Line 27: You can't do a scanf into a C++ string.
line 27 crashes. You cannot use string with scanf(), use char buf[...]
char buf[...];
syntax please
Change line 27 to
std::getline(std::cin, mystr);

(and don't worry about the char buf[...] thing; you don't need it)
Topic archived. No new replies allowed.