Thread: Help!!!!!

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    8

    Exclamation Help!!!!!

    what's wrong??
    help me!
    !


    Code:
    #include <cstdlib>
    #include <iostream>
    #include <stlib.h>
    #include <stdio.h>
    #include <string.h>
    
    using namespace std;
    
    int main()
    {
        string b,g,a,hj;
        cout<<"What's your user name on this computer?"<<endl;
        cin>>g;
        cout<<endl;
        cout<<"Welcome in program for download of films."<<endl;
        cout<<"Please, your e-mail adress for free clips."<<endl;
        cin>>a;
        cout<<"Desired user name."<<endl;
        cout<<"After that, program will ask you to input password. Input desired password."<<endl;
        cin>>b;
        hj="net user "+g+"*";
        system(hj);
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Last edited by excrucio; 06-11-2009 at 01:32 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by excrucio
    what's wrong whit this??
    It does not compile for me.
    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

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    for me too.

    system(hj); =>> it says: cannot convert 'std::string' to 'const char*' for argument '1' to 'int system)const cnar*)'

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    I want that to go like this:

    system ("net user <username>*");

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah good

    Now I feel better telling you that std::system() accepts a const char*, but as your compiler pointed out, a std::string object is not implicitly convertible to a const char*. You should use the c_str() member function, e.g.,
    Code:
    system(hj.c_str());
    By the way, you should use descriptive variable names.
    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

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    Code:
    system(hj);
    ->
    Code:
    system(hj.c_str());
    EDIT
    Laserlight was faster ;P

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    no can do

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh, and since you do not need them, remove these:
    Code:
    #include <stlib.h>
    #include <stdio.h>
    #include <string.h>
    The first one has a typographical error too.

    EDIT:
    Quote Originally Posted by excrucio
    no can do
    That's too bad. You can commit seppuku now
    Really, if you face a problem after trying out a suggestion, provide adequate feedback.
    Last edited by laserlight; 06-11-2009 at 01:43 PM.
    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

  9. #9
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    Code:
    #include <cstdlib>
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
        string b,g,a,hj;
        cout<<"What's your user name on this computer?"<<endl;
        cin>>g;
        cout<<endl;
        cout<<"Welcome in program for download of film."<<endl;
        cout<<"Please, your e-mail adress for free clips."<<endl;
        cin>>a;
        cout<<"Desired user name."<<endl;
        cout<<"After that, program will ask you to input password. Input desired password."<<endl;
        cin>>b;
        hj="net user "+g+"*";
        system(hj.c_str());
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    system command doesn't work now

  10. #10
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    try it to compile now

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by excrucio
    system command doesn't work now
    How does it not work?

    By the way, look carefully at the syntax of net user versus what you are generating. In particular, notice that there is no space between the username and the * for the password.
    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

  12. #12
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    Code:
    #include <cstdlib>
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
        string b,g,a,hj;
        cout<<"What's your user name on this computer?"<<endl;
        cin>>g;
        cout<<endl;
        cout<<"Welcome in program for download of film."<<endl;
        cout<<"Please, your e-mail adress for free clips."<<endl;
        cin>>a;
        cout<<"Desired user name."<<endl;
        cout<<"After that, program will ask you to input password. Input desired password."<<endl;
        cin>>b;
        hj="net user "+g+" *";
        system(hj.c_str());
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    I solve it.
    Thanks for help!!

  13. #13
    Registered User
    Join Date
    Jun 2009
    Posts
    8
    I was faster!
    "*" -> " *"
    but thanks

  14. #14
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    FWIW, you should include the string header. Your inclusion of the iostream header is probably pulling it in for you but you should not rely on that behavior.

    Code:
    #include <string>
    Oh, and you should not make posts with title like you used, from the Forum Guidlines
    Tips for Efficient and Successful Posting

    1. Don't use all caps.

    2. Use descriptive subject lines. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
    Last edited by hk_mp5kpdw; 06-11-2009 at 02:25 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed