我一直在努力组合两段代码,以便可以将第一段的输出用作第二段的输入。
第一个程序(生成我想重用的数字):
$ cp -a security/. site/dist/
$ mv site/dist/[index]*.html site/dist/index.html
mv: cannot stat 'site/dist/[index]*.html': No such file or directory ERROR: Job failed: exit code 1
第二个程序(使用数字来生成结果):
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
// n is the number of nodes, d is the diameter
int n, d;
cout << "Enter the number of nodes and the diameter of the graph: ";
cin >> n >> d;
int numberofxcycles = floor((n+6*d-2)/(4*d));
int xcycles[numberofxcycles];
int i;
for(i = 0; i < numberofxcycles; i++){
xcycles[i] = floor((n-2)/(4*d)) + i;
}
int v, cycle, cycle2;
for(v = 1; v <= n; v++){
cycle = 0;
cycle2 = 0;
for(i = 0; i < numberofxcycles; i++){
if(v+(xcycles[i]+1) > n){
cycle = n;
}
if(v-(xcycles[i]+1) < 1){
cycle2 = n;
}
cout << v << " " << v+(xcycles[i]+1)-cycle << endl;
cout << v << " " << v-(xcycles[i]+1)+cycle2 << endl;
}
}
}
两个程序都可以正常运行。我试图合并这两个程序,但是每当我运行它时,都会弹出一个对话框,提示“ programe.exe已停止工作”。
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
vector<vector<int> >GRAPH(100);
inline void print_path(vector<int>path)
{
cout<<"[ ";
for(int i=0;i<path.size();++i)
{
cout<<path[i]<<" ";
}
cout<<"]"<<endl;
}
bool isadjacency_node_not_present_in_current_path(int node,vector<int>path)
{
for(int i=0;i<path.size();++i)
{
if(path[i]==node)
return false;
}
return true;
}
int findpaths(int source, int target, int totalnode, int totaledge )
{
vector<int>path;
path.push_back(source);
queue<vector<int> >q;
q.push(path);
while(!q.empty())
{
path=q.front();
q.pop();
int last_nodeof_path=path[path.size()-1];
if(last_nodeof_path==target)
{
cout<<"The Required path is:: ";
print_path(path);
}
else
{
print_path(path);
}
for(int i=0;i<GRAPH[last_nodeof_path].size();++i)
{
if(isadjacency_node_not_present_in_current_path(GRAPH[last_nodeof_path][i],path))
{
vector<int>new_path(path.begin(),path.end());
new_path.push_back(GRAPH[last_nodeof_path][i]);
q.push(new_path);
}
}
}
return 1;
}
int main()
{
//freopen("out.txt","w",stdout);
int T,N,M,u,v,source,target;
scanf("%d",&T);
while(T--)
{
printf("Enter Total Nodes & Total Edges\n");
scanf("%d%d",&N,&M);
for(int i=1;i<=M;++i)
{
scanf("%d%d",&u,&v);
GRAPH[u].push_back(v);
}
printf("(Source, target)\n");
scanf("%d%d",&source,&target);
findpaths(source,target,N,M);
}
//system("pause");
return 0;
}
请帮助!我是C ++的新手,我正在尝试为我的数学研究实现此程序。如果需要,我可以提供有关数学以及程序功能的更多详细信息。谢谢!
答案 0 :(得分:0)
为什么不使用argc
和argv[]
作为第二个程序的main()
函数的输入来编写命令行界面。
int main(int argc, const char* argv[]) {
for (int i = 0; i < argc; ++i) {
T = argv[i];
}
while (--T) {
}
}
如果同时编译这两段代码,则可以在命令行中运行第一个程序,并将输出从第一个程序传输到第二个程序。在Bash中,这是通过使用管道运算符'|'实现的:
./program1 | ./program2
或通过输出重定向:
./program2 < ./program1