C++如何从主系统移动代码
C++ how can I move a code from the main
我对C++知之甚少所以我有这个代码
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);
我被要求将其移到主线之外,然后在主线中调用它现在我不知道该怎么办你能告诉我我应该遵循的步骤是什么吗请尽可能具体,我真的很不擅长这件事
谢谢
您必须创建一个函数并在 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
}
这就是创建函数的工作方式,基本上是 C++ 中任何代码的编写方式。 有时函数出现在主文件之外的文件中,但基本相同。
查看C++函数。我假设你有如下内容。
int main(){
//***your stuff
return
您需要以下内容。
void function(){
//**your stuff
return;
}
int main(){
function();
return;
}
当程序启动时,它将自动转到主,当它到达呼叫时: 函数();
它将控制权传递给包装在其中的代码
void function(){
return;
}
如果我理解正确,我认为您只需要将代码放入函数中,如下所示:
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);
}
然后,您可以使用 CodeFunction()
从main
调用它。
请记住将其放在main
函数上方,或者如果它低于此值,则在上面声明它main
使用
void CodeFunction();
希望这有帮助。
您需要编写一个函数,将代码移动到该函数,然后从 main - http://www.cplusplus.com/doc/tutorial/functions/调用该函数
相关文章:
- C++,系统无法执行指定的程序
- 将对象移动到std::shared_ptr
- 何时在引用或唯一指针上使用移动语义
- 在UNIX系统中使用DIR查找文件的字节大小
- 如何从具有移动语义的类对象中生成共享指针
- 将shared_ptr移动到<StructA>shared_ptr<变体<结构A、结构 B>>
- 错误处理.将系统错误代码映射到泛型
- C / C++ 移位/偏移/向左或向右移动位图?
- 当系统的卷被修改时,如何修改WASAPI环回捕获卷
- MSVC将仅移动结构参数解释为指针
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 自定义先决条件对移动分配运算符有效吗
- 在C++游戏中与库存系统作斗争
- 具有文本角色扮演功能的移动系统
- 我是否缺少<实验/文件系统>移动操作?
- "<某些系统标头>:错误:"<在此处插入函数>"在移动源文件后不是"std"的成员
- C++如何从主系统移动代码
- C++/CLI:文件系统观察器移动或复制非空文件夹
- 在运行Symbian的移动设备上显示系统信息
- Cocos2d粒子系统不跟随移动和旋转的摄像机