Author Topic: C++ Read File  (Read 3680 times)

yourlife

  • Member
  • **
  • Posts: 52
  • Kudos: 2
  • The One And Only Autistic Albino!
    • Yourlife
C++ Read File
« on: 22 August 2010, 21:09 »
Hiya.
I want C++ to output the contents of a text file.
The text file is like this:
Quote
Bugs Bunny, Daffy Duck, Tree House
Steve Jobs, Bill Gates, Bedroom
And I want my C++ (CUI app) to display it like this:
Name       | Friend     | Place
-----------|------------|------------
Bugs Bunny | Daffy Duck | Tree House
Steve Jobs | Bill Gates | Bedroom

Obviously the two top lines can be done with C Out, but its the actual file that I can't do.

P.s. I'm new to C++!
P.s.s. I'm using Windows, Visual C++ 2010.
By the worlds one and only Albino with Aspergers! Yes I'm awesome
http://www.yourlifegroup.org

Refalm

  • Administrator
  • Member
  • ***
  • Posts: 5,183
  • Kudos: 704
  • Sjembek!
    • RADIOKNOP
Re: C++ Read File
« Reply #1 on: 24 August 2010, 14:51 »
I don't know anything about C++. So I made an AWK script instead.
Code: [Select]
#!/bin/sh
gawk '
BEGIN { FS = ","; print " Name        | Friend      | Place\n ------------|-------------|------------" }
{ printf "%12s |%12s |%12s\n", $1, $2, $3 }
' looney.txt
« Last Edit: 24 August 2010, 15:05 by Refalm »