Hello all:

I have written a function that gets data (numbers) from a text file.

My function works by taking a line from the text file, discarding unnecessary symbols, and putting the numbers into a vector. Here's a snippet:

// Get data from text file. Values then put into one vector.

if( line == theData ){
std::getline( file, line );
line.erase(remove( line.begin(), line.end(), '\'' ), line.end() );
std::istringstream streamLine( line );

The problem is, the text file looks ugly. I have to put the data on a single line. There are labels on the line above. When there are many numbers, the labels and the data are wrapped around to the next lines. So it is very hard for a person using the file to tell which label goes with which number on the line below.

What I want to do is have a list (vertical) of labels with the correct numbers next to them. But I'm not sure if this would be possible. From what I have seen, it seems like data always have to be on the same line. I need a result like:

Apple: 1
Orange: 2
Banana: 3

Result vector has elements 1,2,3

Thanks for any help.

Edited by Annettest: n/a

6 Years
Discussion Span
Last Post by haider885

Seems awfully similar to this thread.
Anyway, post all the code that you have written so far. Not only snippets. And a sample of the input text file. Not just the required output.


That would be my brother. We're both stuck on streams. Any resources/texts would be good to know about.

Edited by Annettest: n/a


how to access documents from "D" and then i want to store them in queu and then print...plz answer me


Try this one....
Maybe its help....

 ifstream Read;
 char output[100];
 if (Read.is_open()) {
 while (!Read.eof()) {

    Read >> output;

This question has already been answered. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.