newbie question about system("xy.exe")

N

Neil Brown

Hello all,

Firstly sorry if this is the wrong ng - I think I've found the right one

I'm trying to call an exe file from c++,

#include "stdafx.h"

int main(int argc, char* argv[])
{
printf("Hello World!\n");
system("dir");
return 0;
}



I think I'm not using the right headers? I'm getting 'undeclared
identifier' when compiling - I don't have MSDN, and am trying to find
out which header files to use to get 'system' to work - is there a c
command reference on the web I can search? of course any search on the
web finds a lot of instances of the word 'system'

Many thanks in advance, I'm sure it's easier than I'm making it.
 
J

John Harrison

Neil Brown said:
Hello all,

Firstly sorry if this is the wrong ng - I think I've found the right one

I'm trying to call an exe file from c++,

#include "stdafx.h"

int main(int argc, char* argv[])
{
printf("Hello World!\n");
system("dir");
return 0;
}



I think I'm not using the right headers? I'm getting 'undeclared
identifier' when compiling - I don't have MSDN, and am trying to find
out which header files to use to get 'system' to work - is there a c
command reference on the web I can search? of course any search on the
web finds a lot of instances of the word 'system'

Many thanks in advance, I'm sure it's easier than I'm making it.

stdafx.h is not a standard header, and I can't see any reason why you would
need it (although I don't know what is in it).

The two headers you do need are <stdio.h> (for printf) and <stdlib.h> (for
system). I would include those and throw stdafx.h away.

A good reference is for C++ is http://www.dinkumware.com/refxcpp.html.

BTW this is a C++ group, if you want to ask question specifically about C
try
john
 
A

Allan Bruce

Neil Brown said:
Hello all,

Firstly sorry if this is the wrong ng - I think I've found the right one

I'm trying to call an exe file from c++,

#include "stdafx.h"

Don't use this unless you are using MFC (I think)
instead you should have:
#include <cstdio>
Allan
 
J

Jack Klein

Don't use this unless you are using MFC (I think)
instead you should have:
#include <cstdio>
Allan

....and also include <cstdlib> for the declaration of std::system().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top