Would... This work?

This is a discussion on Would... This work? within the C++ Programming forums, part of the General Programming Boards category; It seems too simple, but it works when I change the path to a folder on my computer... I don't ...

  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 03:06 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,454
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,288
    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
    21,310
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    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, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21