You are not logged in. Please login at www.codechef.com 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

0★shubhgoyal5
56521
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

link

answered 27 Jan '16, 00:57

ankg's gravatar image

3★ankg
2113
accept rate: 33%

Use freopen function: http://www.cplusplus.com/reference/cstdio/freopen/

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

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

link

answered 26 Jan '16, 18:20

vsp4's gravatar image

6★vsp4
1.2k138
accept rate: 28%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×1,380
×183
×40
×14

question asked: 26 Jan '16, 16:09

question was seen: 1,083 times

last updated: 27 Jan '16, 00:57