-7

I have little knowlage in C++ so I have this code

bool is_successful = true;
ex_file_licensing exFileLicence;
std::string flexLMfilePath;
flexLMfilePath.append("C:/Desktop/QA-program/testsuite/tmp/");
std::string Message = exFileLicence.checkLicense(DI_MF,flexfilePath,is_successful);

and I was asked to move it outside the main and then call it in the main and now I have no idea what to do Could you please tell me what are the steps that I should follow please be as specific as possible, I'm really bad at this thing

Thanks

Samsara
  • 37
  • 1
  • 2
  • 6
  • 7
    You need to write a function. But really, if you have literally no experience with C++, you should get a [decent introductory book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Oliver Charlesworth Jun 07 '12 at 14:23
  • For more information on how to create functions, please see http://www.cplusplus.com/forum/beginner/35690/ – Hans Z Jun 07 '12 at 14:23

4 Answers4

2

You must create a function and call that function inside main:

void foo(); //this is called a function prototype

main()
{
...
foo() //your function in place of that code
}

void foo()
{
...//the code originally in main.  This is called your function definition
}

this is how creating functions works and is basically how any code in c++ is written. Sometimes the functions appear in files outside the main file but its basically the same.

NKamrath
  • 536
  • 3
  • 9
1

Check out C++ Functions. I'm assuming you have something as follows.

int main(){
    //***your stuff
return

You need the following.

void function(){
    //**your stuff
return;
}

int main(){

      function();

return;
}

When the program starts it will automatically go to main and when it reaches the call: function();

It will pass control to the code wrapped within

void function(){

return;
}
Florin Stingaciu
  • 8,085
  • 2
  • 24
  • 45
0

If I understand correctly I think you just need to put the code in a function, like this:

void CodeFunction()
{
    bool is_successful = true; 
    ex_file_licensing exFileLicence; 
    std::string flexLMfilePath; 
    flexLMfilePath.append("C:/Desktop/QA-program/testsuite/tmp/"); 
    std::string Message = exFileLicence.checkLicense(DI_MF,flexfilePath,is_successful); 
}

and you can then call it from main by using CodeFunction().

Remember to put this above the main function, or if it's below declare it above main using

void CodeFunction();

Hope this helps.

Bali C
  • 30,582
  • 35
  • 123
  • 152
0

You need to write a function, move the code to the function and then call the function from main - http://www.cplusplus.com/doc/tutorial/functions/

Superman
  • 3,027
  • 1
  • 15
  • 10