Thread: Would... This work?

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    Would... This work?

    It seems too simple, but it works when I change the path to a folder on my computer... I don't want to test it... Just asking if people think it would work. Thanks guys.

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        system("dir &#37;SystemRoot%");
        return EXIT_SUCCESS;
    }
    Last edited by laserlight; 02-11-2008 at 04:06 AM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so you want somaone to test it for you?

    make another env var, point it to manually build folder with subdirectories and different file types: system, hidden, read only

    and use this env var for youself...

    and I hope you are not planning of giving you program to you friend to test it...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Don't run that. It deletes your hard drive.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Don't post stuff like that here, it's like a "Wet Paint" sign. You can just about guarantee some idiot will touch it just to see if the sign is correct.

    You better not be planning on writing a malicious program either!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    It will probably work but it will delete our drive (if that was your intention, great!). But if you are planning to send it to your friend as a joke, then you can get arrested. I suggest you don't even compile it.
    Hand over your source code, and nobody gets hurt.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    Quote Originally Posted by vart View Post
    so you want somaone to test it for you?

    make another env var, point it to manually build folder with subdirectories and different file types: system, hidden, read only

    and use this env var for youself...

    and I hope you are not planning of giving you program to you friend to test it...
    I tested it, and it doesn't delete hidden files... BUT the one I posted is not as bad as it you would think. %SystemRoot% for my computer (Compaq, Vista) is the 'Windows' folder. Thats not that bad as there isnt that many files in it... it get's dangerous when you change the path to:
    Code:
    C:
    and instead of just:
    Code:
    /q
    you have
    Code:
    /f /s /q
    That would delete ALL the files on your C: drive not being used, apart from the hidden ones, or in my case, (Vista) some of the system32 files. I shouldve said it too, DONT COMPILE AND RUN THIS GUYS!

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, is this a question concerning C++ or the Windows command prompt?

    Since this is the C++ forum, I edited your code example - there is no need to post a controversial example. So, what is your question again?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This just goes to show that you shouldn't use system. You should rather use standard C/C++ functions or platform specific API.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM