You are not logged in. Please login at to post your questions!


Clubbing a .txt file with a .cpp file

I have a file (.txt) and I have a C++ program based on trie. Now what I need is the search function performs search on data taken form that .txt file. What I should do now to achieve that??

asked 26 Jan '16, 16:09

shubhgoyal5's gravatar image

accept rate: 0%

You can also use a pipe if running from command line without adding anything to your normal C/C++ program. The command is as follows :- (assuming a.out is your program executable)

./a.out < input.txt > output.txt

A '>' or '<' defines the direction of data flow from left to right or vice versa respectively.

Hence, if you wish to output to terminal and only take input from input.txt, your command will be :-

./a.out < input.txt


answered 27 Jan '16, 00:57

ankg's gravatar image

accept rate: 33%

Use freopen function:

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

To take input from input.txt and output to output.txt


answered 26 Jan '16, 18:20

vsp4's gravatar image

accept rate: 28%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 26 Jan '16, 16:09

question was seen: 1,061 times

last updated: 27 Jan '16, 00:57