Re: c++ question

  • From: "Jeremy Hartley" <jeremyhartley@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 15 May 2009 21:05:52 -0700

Hello.

I hope I understood your question correctly. Without an example, the question sounds a bit vague, but I will try to answer based on what I think you are trying to accomplish.

It sounds like you wish to call a function in main and when the function has completed, return execution back in main.

Well, basically, all you need to do to accomplish this is to call the function in main() and once the function has completed, you will be automatically returned to main(), ready to call another function.

For example.

Suppose you have a function that is designed to put a line of text on the screen.

This function may look like this.

void displayLine()
{
cout << "Hey, I am a line of text!" << endl;
} // End displayLine().

Now, providing you have all of your #include statements such as #include <iostream>, and your using statements such as using std::cout; at the top of your file, you could start main like this.

int main()
{
cout << "We are now in main()\n";
cout << "Now calling displayLine()\n";

// now, you can call your displayLine() function.

displayLine();

// when displayLine ends
// the next statement in main will display.

cout << "I am now back in main()\n";

return 0;
} // End Main().


So your output would look like:

We are now in main().
now calling displayLine().
Hey, I am a line of text!
We are now back in main().

Jeremy
----- Original Message ----- From: "Haden Pike" <haden.pike@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, May 15, 2009 8:39 PM
Subject: c++ question


Hi all. I am trying to write a consul application in c++. My problem is that once it executes a function, I want it to return to the main function in this case int main. I am not sure how to accomplish this or maybe I am, it's just evading me for now. *smile* Anyway, thanks in advance for any help.
Haden


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: