-
A couple questions
I have a couple questions. They should be pretty simple to answer, but for a beginner these problems are daunting.
I have some text in cout that has \'s then words, so the compiler gives me these errors...
[Warning] unknown escape sequence '\D'
Is there a way to get around that? It compiles fine, but I don't see the the \'s in my text when the program runs.
Question 2...
I'm just playing around at the moment, trying to get familier with C++. I was making a little console program to scare my friends, I want to make a stupid little program that makes it look like I am deleting all the files on my computer. Something simple.
Such as I will just type delete.exe or something like that. How can I set it up so that there is a brief pause between that and the next line of text which would be something like "Files Deleted Successfully".
Something that would make it look like...
Delete.exe
Deleting...
*Then a few second pause*
Files Deleted.
Sorry if that is a long explanation for something so simple, but thanks in advance for any advice!
-
\ denotes an escape sequence. \n for a newline, \b for backspace, etc. So, when using a \ in your text, use \\. Same goes for " (\").
To pause for a little while, include windows.h and then use the function Sleep( Milliseconds );
- SirCrono6
-
To output a backslash, use "\\" for example:
cout<<"c:\\program files\\somefolder\\etc";
And check the faq on sleeping (although I think you should include <ctime> instead of <time.h>)
Edit: Beaten, although the faq does list other methods for sleeping ;)
-
Thanks guys! Now I can pretend to delete my friends computers!!
They shall ph34r my L337 c0mpt3r Skillz!
-
One more thing...
How come this won't work? Can the == operator only check numbers?
Code:
if (input == file.exe)
cout<<"Test";
I'm using the string variable so that input can hold a whole word. The error I get is...
`file' undeclared (first use this function)
-
If it's a string, you need to put it in quotes.
Code:
if( input == "file.exe" )
{
std::cout << "Test";
}
- SirCrono6
-
-
If it's a character array, you need to use strcmp():
Code:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char one[80], two[80];
cout << "\nEnter the first string: ";
cin >> one;
cout << "\nEnter the second string: ";
cin >> two;
if(strcmp(one, two) == 0) {
cout << "\nThe strings are the same.";
}
}