I need help reading this specific file

I just need help reading a file then everything would finally make sense.

S'mores
2
4 squares graham crackers
1 bar milk chocolate
2 large marshmallows

I can read first line with getline
I have no idea how to read the rest

3-5 lines
are divided like this

amount | shape/size | name

any help would be appreciated
if you'r using streams you can do it like so:
1
2
3
4
5
6
int amount;
std::string shape_size;
std::string name;

f >> amount >> shape_size;
std::getline(f, name);
Sorry, the way i explained that is also confusing to me, 5am isn't the best time for me to be up coding.

I have to read all of it.

string recipe;
int serving;
int amount;
string shape_size;
string name;

S'mores
2
4 squares graham crackers
1 bar milk chocolate
2 large marshmallows

I have tried this;

std::getline(f,recipe)
f >> serving;
f >> amount >> shape_size;
std::getline(f,name)

It's returning the wrong values.
This (with the ignore() adjustment) produces the following output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
  std::ifstream f("t.txt");
string recipe;
int serving;
int amount;
string shape_size;
string name;

std::getline(f,recipe);
f >> serving;
f >> amount >> shape_size;
f.ignore(100, ' '); // Note: this removes the spaces left from the previous line (up to 100)
std::getline(f,name);

  std::cout << recipe << std::endl
    << serving << std::endl
    << amount  << std::endl
    << shape_size  << std::endl
    << name << std::endl;
}
S'mores
2
4
squares
graham crackers
That's not what you want?
Topic archived. No new replies allowed.