运行同一解决方案的另一个项目的项目

run a project of another project of the same solution

本文关键字:项目 另一个 解决方案 运行      更新时间:2023-10-16

我有两个项目,都在同一个解决方案上。

项目#1:基于调试输入执行单个操作。为了简单起见,假设main打印调试输入。

项目#2:我想使用在不同调试上运行的for循环来运行项目#1输入。

我如何才能正确高效地做到这一点?据我所知,不建议从项目#2调用项目#1 exe文件。是否有其他方式运行项目#1::main,而不更改项目#1?仅对项目#2进行了更改。。

谢谢,

高级c++新手。

您不必在单独的项目中执行,您可以使用不同的命令行选项从一个项目中执行所有操作。

对于选项一,可以将命令行运行为:pro.exe debug-print1该项目只是打印参数并退出。

对于第二个选项,您可以创建一个文件,
您可以将所有调试打印放在文件中,并在文件的每一行上迭代,您只需要将其标记为文件,例如用-f filename

下一步是在同一次运行中处理多个文件或调试打印,或文件和打印的组合。

因此,以以下代码为例:

#include <string>
#include <iostream>
#include <fstream>
//process a line function:
void proccess_debug_line(const std::string& debug_line)
{
std::cout<<debug_line<<std::endl;
}
//process file by processing each line:
void process_debug_file(const std::string& debug_file_name)
{
std::string debug_line;
std::ifstream inputfile(debug_file_name);
if(!inputfile)
{
std::cerr<<"error openning file: "<< debug_file_name <<std::endl;    
}
while(std::getline(inputfile, debug_line))
{
//use the process line
proccess_debug_line(debug_line); 
}
}
//argument can be a line, or a file if there is -f  before it.
int main(int argc, char **argv) 
{ 
for(int i=1; i<argc; i++)
{
std::string param = argv[i];
if(param[0] == '-')
{
if(param == "-f") // arguments in form -f filename
{
if(i == argc-1 ) // -f is last arg
{
std::cerr<<"Missing argument for " << param << " option."<<std::endl;
}
else //-f filename
{
std::string filename = argv[++i];
process_debug_file(filename);
}
}
else if(param.substr(0,2)== "-f")// argument in form -ffilename can be legal too
{
std::string filename = &(argv[i][2]);
process_debug_file(filename);
}
else
{
std::cerr<<"Unknown option '" << param << "'"<<std::endl;
++i;
}
}
else //a 'regular' parameter (without -f before it) is a debug print
{
proccess_debug_line(param);
}
}
}
相关文章: