want to create a exe file

want to create a exe file

Page 1 of 1

8 Replies - 1150 Views - Last Post: 07 August 2009 - 02:36 PM Rate Topic: -----

#1 krishnendhuchakra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 17-April 09

want to create a exe file

Posted 07 August 2009 - 10:16 AM

want to creat a exe file but i want to link with ms-dos commands....
i mean how to make a source code of ms -dos command in c++
Is This A Good Question/Topic? 0
  • +

Replies To: want to create a exe file

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1091
  • View blog
  • Posts: 4,572
  • Joined: 09-June 09

Re: want to create a exe file

Posted 07 August 2009 - 12:03 PM

View Postkrishnendhuchakra, on 7 Aug, 2009 - 09:16 AM, said:

want to creat a exe file but i want to link with ms-dos commands....
i mean how to make a source code of ms -dos command in c++

What does that even mean? You just want to execute a program from the dos window?
Was This Post Helpful? 0
  • +
  • -

#3 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: want to create a exe file

Posted 07 August 2009 - 12:18 PM

If you want to compile C++ source files, use MinGW, but if you want to execute commands in C++ codes here is the code:
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main( int argc, char *argv[] )
{
	(void)system( "Put Commands Here" );
  return(0);
}


Hope it helps!

This post has been edited by nathanpc: 07 August 2009 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: want to create a exe file

Posted 07 August 2009 - 12:27 PM

what is the cast to void for? Why not just system("command");

In fact that whole program is odd.

The include files are from C, and yet you use "using namespace std;" which only applies to C++. Your program should look like this:
#include <cstdlib>
#include <cstdio>
using namespace std;

int main( int argc, char *argv[] )
{
	system( "Put Commands Here" );
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#5 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: want to create a exe file

Posted 07 August 2009 - 12:36 PM

But you did nothing different of my answer, because you can include C files, the void is because i like!
Was This Post Helpful? 0
  • +
  • -

#6 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: want to create a exe file

Posted 07 August 2009 - 12:39 PM

Rule of thumb.

You are coding in C++. Use C++. It clutters code to add unneeded code.
Was This Post Helpful? 0
  • +
  • -

#7 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: want to create a exe file

Posted 07 August 2009 - 12:57 PM

OK, thanks for the advice!
Was This Post Helpful? 0
  • +
  • -

#8 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: want to create a exe file

Posted 07 August 2009 - 02:08 PM

View Postnathanpc, on 7 Aug, 2009 - 02:36 PM, said:

But you did nothing different of my answer, because you can include C files, the void is because i like!


You are correct. I didn't do anything really different. I just cleaned it up a little. The C libraries do work in C++ and the cast to void is strange but it is no way an error -- one could even argue that it make it explicit that you know the function returns a value and that you are making the clear choice to ignore it.
Was This Post Helpful? 0
  • +
  • -

#9 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: want to create a exe file

Posted 07 August 2009 - 02:36 PM

It's Ok!
Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1