Thread: Is this normal?

  1. #1
    Banned
    Join Date
    Jun 2005
    Posts
    594

    Is this normal?

    I was just experimenting with idea's and i wrote a program
    to check what another program returns.

    such as if it ran successful my program would display a 0,
    because that what the program main() would return.

    anyways this is the code :

    Code:
    #include <iostream>
    #include <process.h>
    
    using namespace std;
    
    int main()
    {
    	int check;
    	check = system("\"D:\\Documents\\Visual C++ Projects\\variablework\\Debug\\variablework.exe\"");
    	cout << check << endl;
    	cin.get();
    	return 0;
    }
    and this is the code of the program i checked
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	cout << "poop" << endl;
    	return 156;
    }
    Now my question is, when i run the first program and it runs the
    2nd program it displays the return amount in my program like it
    should, but it also displays the word i set in the cout statment of
    the 2nd program. This doesnt seem normal to me. Any insight is
    appreciated.

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    In order to get to "return 156", cout must be called. It's program execution, man. Your first program is calling the second program and using its return value.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Yes i know this but, what im saying is i did not realize because it
    doesnt seem right that the content of program one would be
    displayed in program 2.

    to clear that statment up even more, why does the cout statment
    of program 1, show up in program 2, when all program 2 is doing,
    or should be doing is recieving the return amount and displaying
    it. WHy does it display the cout of program 1 in program 2.

  4. #4
    Banned
    Join Date
    Jun 2005
    Posts
    594
    OK nevermind i see why its doing that during this particular instance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 24
    Last Post: 08-05-2010, 05:30 PM
  2. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. Quick Reply or Normal Reply
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-18-2004, 12:49 PM
  5. difference between register int and normal int
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-25-2003, 04:01 PM