See if the user inputed cls.
Title is the same as Q: lol and my code that I have is:
and im trying to make a console!
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
|
#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
loop:
std::cout << ("C:/Konsole/Commands/>");
scanf ("%s",&mystr);
std::cout << ("\n");
goto loop;
}
|
oh and when i have a space in my input it puts
C:/Konsole/Commands/>sampls man
C:/Konsole/Commands/>
C:/Konsole/Commands/>
and not
C:/Konsole/Commands/>sample man
C:/Konsole/Commands/>
Line 26: You can't do a scanf into a C++ string. scanf only works with C-strings.
To answer your initial question (assuming you leave mystr as a C++ string):
1 2 3
|
if (mystr == "cls")
{ // do something
}
|
This ignores the problem of case sensitivity.
Line 28: You should avoid the use of
goto
. It's a poor practice.
Last edited on
@Abs yes I changed it to while (true) {
}
guest i thougth of batch
Topic archived. No new replies allowed.