Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:02:05+00:00 2026-06-14T11:02:05+00:00

You should use either the C++ string object or C-String for this problem. Read

  • 0

You should use either the C++ string object or C-String for this problem. Read content from a file.
The file format is such that in each line: 1) there are three columns, and 2) each column is delimited
by |.
Output each line to stdout. The first column width should be 15, the second column width should be
8, and the third column width should be 6. If the line starts with a #, you should skip it. Moreover,
the second column should be displayed to 2 decimal places.
There might be more than 3 rows; you cannot assume only 3 rows. However, you can assume that
there are only 3 columns.
Sample input

#Test file one
C1|c2|c4
Xyz|1.2|100
Abc|5.5|200

So, given that program outline (I am not asking for you to write my code! 🙁 ) here are my thoughts about what to do…
multidimensional array, but there can be more than three rows so with that variable I don’t think I could do a multidimensional array because of that.

I also thought about reading in each line, separating it up, formatting it and then printing it out, worrying about only each line at a time. I’m figuring it to be the best way possible, but I’m open to doing anything by suggestions. I think I would do it by using some sort of end of line “delimiter”.

The only other problem I can find is that I’m supposed to ignore and skip lines based on if the leading character is a #. I’m not sure how to do that either, I think the ignore() function is a way but as I understand it starts skipping things until your limit is reached or the deliminator is found. I don’t think there is a way, using that function, to find the delim character first and then skip everything to the EOL after it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:02:06+00:00Added an answer on June 14, 2026 at 11:02 am

    You don’t need to store the information in array, you can read and output as it goes. For example a skeleton could look something like so

    string line;
    ifstream inputStream("data.txt");
    
    while( getline(inputStream, line) ){ //grab line if possible
     std::vector<std::string> tokens = parseLine( line, '|'); //parse line using '|' as delim
     //if !tokens.empty && tokens[0][0] != '#'
       //print tokens[i] accordingly 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a little confused as to which one I should use. I think either
I've read I should use money , but in todays fast paced world maybe
Why sometimes I should use block and other times &block inside functions that accept
I wonder how I should use the GTree (from GLib) to store data? Every
I wonder why I should use: puts In folder #{File.join ENV[HOME], projects} Instead of:
I don't know which title I should use for this question. I have a
I have a couple of classes (for this example anyway) that use code first
NSString *string=[temp objectAtIndex:row]; [temp removeObjectAtIndex:row]; The object from which string is created no longer
I know you should use POST whenever data will be modified on a public
I know you should use a StringBuilder when concatenating strings but I was just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.