Hey, I was wondering what the code was to open a program using C++?
so basically writing a program that opens a program.
any help would be great :)

Since you didn't mention what compiler or OS you're using, the only suggestion I can make is the std::system function from <cstdlib>. Look that up in your standard library reference.

sorry, I'm using Visual studio express 2010 on Windows 7

sorry, I'm using Visual studio express 2010 on Windows 7

Is std::system insufficient?

god this is going to sound stupid but I'm really new to this so could you tell me how to use it in very small words?
sorry

I tried that and I couldn't find a straight answer
thought it might be best to ask someone who knew what they were doing

god this is going to sound stupid but I'm really new to this so could you tell me how to use it in very small words?
sorry

Sorry, but if you're really new to this then you won't understand how to do it. You'll need to use specific functions relating to the operating system you're using in order to open a file/program like that.

If some one else knows another way then go and prove me wrong, but I think it takes a little more knowledge to do such a task like that.

I'm also new to this and that's why I'm letting you know it's not exactly easy to understand. I can't do it but just letting you know it's not exactly "beginner" level.

ok :) thanks.
I'm just trying to write fairly simple things at the moment.
most of the code I've used is written on my bed room wall

ok :) thanks.
I'm just trying to write fairly simple things at the moment.
most of the code I've used is written on my bed room wall

Try doing easier things to get the ease and hang of it like input and outputs on to the console window.

Or small Windows API programming functions like MessageBox.

do you know where I can find the source for any of these?

I tried that and I couldn't find a straight answer

That's bull. The first hit from that search string takes you directly to a reference page with a full code example! If you can't copy/paste/compile a five line program, you need to drop back to the hello world program and start again.

Now if you still want a straight answer, ask a straight question. Acting like a clueless idiot isn't going to encourage people who know what they're doing to waste time on you.


p.s. spoonlicker is leading you astray. Let's stay on topic and I can help you write simple code to run another program from your code.

Acting like a clueless idiot isn't going to encourage people who know what they're doing to waste time on you.

Wow, don't you think that's a little harsh? This person is obviously a beginner and can't understand the whole concept so calling them an idiot is being a little arrogant.

I offered tips and advice to help them better understand basic functions so they can work their way up to more complicated ones like the one they asked. You don't have to be rude and insult people.

do you know where I can find the source for any of these?

lol no source. It's easy to remember and use your self. Trying to nab source codes won't make you a good programmer. It's best to write things out yourself from scratch and know and remember what things do.

But any ways, if you really want some help understanding the codes and how they work, as far as what I can teach you, you let me know.

Wow, don't you think that's a little harsh?

Nope.

so calling them an idiot

Try reading for comprehension. "You're acting like an idiot" is quite a different statement than "you're an idiot". The former is a strongly worded slap on the wrist meant to encourage a change of behavior. The latter is a pointless personal insult. See the difference now?

is being a little arrogant.

I'm more than a little arrogant, thanks.

I offered tips and advice

Which were wrong. The basic solution is dead easy, and doesn't require any OS-specific libraries:

#include <iostream>
#include <cstdlib>
#include <string>

int main()
{
    std::string path;

    std::cout<<"Enter the path for a program to run: ";

    if (getline(std::cin, path))
        std::system(path.c_str());
}

On a Windows system? Run that code and type "notepad".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.