By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,435 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,435 IT Pros & Developers. It's quick & easy.

what is piping in c++

P: 5
can anyone explain me what is piping in C++ programming?

for example
invoice.exe < purchase.dat > statement.txt

do i replace that where all the cin statements? i created a text file called purchase.dat with values:

gameboy 149.99 1
ipod nano 220.99 2
DVD-player5 60.95 1
rubics cube 8.85 5

so i.e. below is some coding tat is in working progress. i able to make it tat it prints price, cost, quantity, and product id. i have to use piping. where do i put this statement: invoice.exe < purchase.dat > statement.txt
in the code?

Expand|Select|Wrap|Line Numbers
  1.            for (int i = 0; i <= maxitems; i++)
  2.            {
  3.                cout << "product: ";
  4.                getline(cin, productid);
  5.                cout << "quantity; ";
  6.                cin >> quantity;
  7.                cout << "price: ";
  8.                cin >> price;
  9.  
  10.                cost = quantity * price;
  11.                totalcost = totalcost + cost;     
  12.            cout << setw(34) << productid << setw(10) << quantity << setw(10) << price << setw(12) << cost << endl;           
  13.            } cout << "Total: " << totalcost << endl; 
May 27 '07 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
What you have is not piping.

This example of yours:
invoice.exe < purchase.dat > statement.txt
is called redirection.

This is done on the command line where you execue yout program invoide.exe.

A command line argument of <purchase.dat redirects the input to your prgram so the keyboard (stdin) is replaced by the disc file purchase.dat. You need to change nothing in your code. Redirecting input just causes all of your cin statements to get input from the disc file rather than the keyboard.

Likewise, >statement.txt redirects the output (stdout) of your pogram from the monitor to the disc file statement.txt. Whatever cout displays on the screen is redirected to the disc file statement.txt instead.

Be aware than when you redirect output, your screen will be blank as all of the displays are written to a disc file.
May 27 '07 #2

P: 5
What you have is not piping.

This example of yours:


is called redirection.

This is done on the command line where you execue yout program invoide.exe.

A command line argument of <purchase.dat redirects the input to your prgram so the keyboard (stdin) is replaced by the disc file purchase.dat. You need to change nothing in your code. Redirecting input just causes all of your cin statements to get input from the disc file rather than the keyboard.

Likewise, >statement.txt redirects the output (stdout) of your pogram from the monitor to the disc file statement.txt. Whatever cout displays on the screen is redirected to the disc file statement.txt instead.

Be aware than when you redirect output, your screen will be blank as all of the displays are written to a disc file.
so how do i apply invoice.exe < purchase.dat > statement.txt
in the program?
May 28 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
You do not apply this inside the program.

You specify this at the OS command prompt when you run your program.
May 28 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.