Quantcast
Channel: User luke - Stack Overflow
Viewing all articles
Browse latest Browse all 31

Answer by luke for Pipe an input to C++ cin from Bash

$
0
0

g++ main.cpp compiles it, the compiled program is then called 'a.out' (g++'s default output name). But why are you getting the output of the compiler?I think what you want to do is something like this:

#! /bin/bash# Compile to a.outg++ main.cpp -o a.out# Then run the program with input.txt redirected# to stdin and the stdout redirected to output.txt./a.out < input.txt > output.txt

Also as Lee Avital suggested to properly pipe an input from the file:

cat input.txt | ./a.out > output.txt

The first just redirects, not technically piping. You may like to read David Oneill's explanation here: https://askubuntu.com/questions/172982/what-is-the-difference-between-redirection-and-pipe


Viewing all articles
Browse latest Browse all 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>