Thread: A couple questions

  1. #1
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50

    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!

  2. #2
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    \ 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
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    Thanks guys! Now I can pretend to delete my friends computers!!

    They shall ph34r my L337 c0mpt3r Skillz!

  5. #5
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    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)

  6. #6
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    If it's a string, you need to put it in quotes.

    Code:
    if( input == "file.exe" )
    {
      std::cout << "Test";
    }
    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  7. #7
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    Ah, thanks.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.";
        }
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple of Questions About Classes
    By bengreenwood in forum C++ Programming
    Replies: 3
    Last Post: 05-20-2009, 02:50 PM
  2. Couple of Questions
    By toonlover in forum Windows Programming
    Replies: 10
    Last Post: 07-14-2006, 01:04 AM
  3. Couple of simple directdraw questions.
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 05-25-2005, 07:55 AM
  4. A couple of questions that someone might know the answer to...
    By Finchie_88 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-15-2005, 08:26 AM
  5. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM