Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ Help


ghost's Avatar
0 0

Hey, I'm making a program in C++ I know the basics of C++, well I know enough to do what I'm doing. My problem is, when I use system I get an error saying: implicit declaration of function `int system(…)'

I've used the system command before and I don't know what's wrong with it, any help will be appreciated very much.

DarkPanther


ghost's Avatar
0 0

Don't put the int in front of it… You only need to do that when you're making your own function.


ghost's Avatar
0 0

I'm not, that's the error I'm putting:

system("mkdir Folder1");

DarkPanther


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

Have you included windows.h?


ghost's Avatar
0 0

Yeah, I tried with and without… don't work.

DarkPanther


ghost's Avatar
0 0

Oh, I got it to work :)

#include<string>

I really really didn't think you needed that to use system

Oh well hehe

DarkPanther


ghost's Avatar
0 0

You don't… technically, it should compile without like all header files, but it's usually standard to include <cstdlib>.


ghost's Avatar
0 0

Care to explain ? Im new to C++ started about a week ago.

DarkPanther


ghost's Avatar
0 0

Well, most compilers (that I've used anyways) still provide the system() command without ever having to include any header file besides <iostream>. The header file you included should not have affected it all seeing as the <cstdlib> header file handles process control as well as others, which means it is responsible for the system() command. As for system_meltdown's suggestion, well we all know he means well, but in the end it is practically useless and would just bloat your program with an un-needed inclusion.

http://www.cplusplus.com/ref/cstdlib/

~T


ghost's Avatar
0 0

system_meltdown wrote: Have you included windows.h?

windows.h is for C, I think C++ is just #include<windows> im not sure though.


lukem_95's Avatar
Member
0 0

DarkMantis wrote:

windows.h is for C, I think C++ is just #include<windows> im not sure though.

You can use either. or even #include<windows.h>