小编Eri*_*lan的帖子

管道输入/输出

这个问题来自我试图实施以下指令:

Linux管道作为输入和输出

如何使用管道在两个程序之间发送一个简单的字符串?

http://tldp.org/LDP/lpg/node11.html

我的问题在于:Linux管道作为输入和输出,但更具体.

基本上,我试图取代:

/directory/program < input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)

在C++中使用管道以避免使用硬盘驱动器.这是我的代码:

//LET THE PLUMBING BEGIN 
int fd_p2c[2], fd_pFc[2], bytes_read;
    // "p2c" = pipe_to_child, "pFc" = pipe_from_child (see above link)
pid_t childpid;
char readbuffer[80];
string program_name;// <---- includes program name + full path
string gulp_command;// <---- includes my line-by-line stdin for program execution
string receive_output = "";

pipe(fd_p2c);//create pipe-to-child
pipe(fd_pFc);//create pipe-from-child
childpid = fork();//create fork

if (childpid < 0)
{
    cout << "Fork failed" << endl;
    exit(-1);
} …
Run Code Online (Sandbox Code Playgroud)

c++ linux pipe

6
推荐指数
1
解决办法
4万
查看次数

从Fortran调用C++(链接问题?)

我真的需要你的帮助!我正处于截止日期,我正在努力学习,以完成一些工作.现在已经有一周多了,我正在处理看似简单的问题,但我无法在线成功实施解决方案.

长话短说:我需要从F77调用C++代码.我正在用g ++和gfortran编译.我是一个完整的新手来制作文件.当这些代码被编译为各自程序的一部分时,它们没有错误(我从我的C++代码中获取函数,而不是main(),并尝试将其与fortran代码一起使用).这是我得到的:

C++代码:

#include <cmath>
#include <vector>
using namespace std;

extern"C" double ShtObFun(double x[], int &tp)
{
    return //double precision awesomeness
}
Run Code Online (Sandbox Code Playgroud)

Fortran代码:

    subroutine objfun(nv, var, f, impass)
    implicit real(8) (a-h,o-z), integer (i-n)
c   initializations including tp, used below

    f = ShtObFun(var, tp)

    return
    end
Run Code Online (Sandbox Code Playgroud)

Makefile(仅显示上面列出的文件):

all:
    g++ -c Objective_Functions.cpp
    gfortran -c -O3 opcase1.f
    gfortran opcase1.o Objective_Functions.o -fbounds-check -lstdc++ -g -o Program.out
    rm *.o
Run Code Online (Sandbox Code Playgroud)

错误:

opcase1.o: In function 'objfun_':
opcase1.f:(.text+0xbd): undefined reference to 'shtobfun_'
collect2: ld returned 1 exit …
Run Code Online (Sandbox Code Playgroud)

c++ linker fortran makefile

3
推荐指数
1
解决办法
4664
查看次数

使用Fortran 77子程序作为独立程序,从C++调用

所以我一直在像瘟疫一样避开Fortran,但最后我的时间到了......我需要参与其他人的Fortran代码(让我们称之为程序A)并用它做两件事:

(1)将其与第三人的Fortran代码合并(让我们称之为程序B),以便B可以调用A

(2)将它与我的C++代码(程序C)合并,以便C可以调用A.

B和C是优化算法,A是基准函数的集合......但在所有可怕的事情发生之前,我必须首先编译我需要的A部分.我需要的所有A子程序都包含在一个文件中.我已根据我上网的信息(例如在代码中添加"IMPLICIT NONE"并使其适合gfortran)进行了整形.但是我有两个顽固的错误和一个警告(我会留下另一个帖子的警告).

这是我目前正在编译它的方式(通过Makefile):

all:
    gfortran progA.FOR
    g++ -c progC.cpp
    g++ -o Program.out progA.o progC.o
    rm *.o
Run Code Online (Sandbox Code Playgroud)

但第一行未能完成以下错误,

第一个错误:

SUBROUTINE TP1(MODE)
1
Error: Unclassifiable statement at (1)
Run Code Online (Sandbox Code Playgroud)

相关代码(从文件顶部开始):

      IMPLICIT NONE  
      INTEGER    NMAX,MMAX,LMAX,MNNMAX,LWA,LIWA,LACTIV,N,NILI,NINL,
     /           NELI,NENL,NEX, MODE              
      PARAMETER (NMAX   = 101, 
     /           MMAX   = 50, 
     /           LMAX   = 50, 
     /           MNNMAX = NMAX + NMAX + MMAX + 2,
     /           LWA    = 2*NMAX*NMAX + 33*NMAX + 10*MMAX + 200,
     /           LIWA   = MMAX + NMAX + 150,
     /           LACTIV = …
Run Code Online (Sandbox Code Playgroud)

c++ fortran compiler-errors

2
推荐指数
1
解决办法
223
查看次数

使用FILE*的二进制文件I/O

我一直在网上搜索,实现如图所示的信息,但由于我不明白的原因,我无法让这个非常简单的代码工作.它应该是一个简单的健全检查.我正在使用FILE*来获得速度(速度是这里的优先级).一,变量......

#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{

//Declaration
int g = 1, dim_hi = 5, pop = 6;//variables I'll use to write to binary file
char OA = 'D';//variable I'll use to write to binary file

const short d_size = sizeof(double);
const short c_size = sizeof(char);
const short i_size = sizeof(int);
FILE * outFile;

int read_g = 0, read_dim = 0, read_pop = 0;//variables I'll use to READ from file
char read_oa …
Run Code Online (Sandbox Code Playgroud)

c c++ binaryfiles

1
推荐指数
1
解决办法
327
查看次数

标签 统计

c++ ×4

fortran ×2

binaryfiles ×1

c ×1

compiler-errors ×1

linker ×1

linux ×1

makefile ×1

pipe ×1