what is piping in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noob2008
    New Member
    • May 2007
    • 5

    what is piping in c++

    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?

    Code:
               for (int i = 0; i <= maxitems; i++)
               {
                   cout << "product: ";
                   getline(cin, productid);
                   cout << "quantity; ";
                   cin >> quantity;
                   cout << "price: ";
                   cin >> price;
               
                   cost = quantity * price;
                   totalcost = totalcost + cost;     
               cout << setw(34) << productid << setw(10) << quantity << setw(10) << price << setw(12) << cost << endl;           
               } cout << "Total: " << totalcost << endl;
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What you have is not piping.

    This example of yours:
    Originally posted by noob2008
    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.tx t 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.

    Comment

    • noob2008
      New Member
      • May 2007
      • 5

      #3
      Originally posted by weaknessforcats
      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.tx t 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?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You do not apply this inside the program.

        You specify this at the OS command prompt when you run your program.

        Comment

        Working...