-1

I am trying to teach myself C++ with some programming assignments. Trying to learn using stacks but I am unsure how to push values from a txt file into a stack.

Let' say I have the following text file:

16 24 25 3 20 18 7 17 4 15 13 22 2 12 10 5 8 1 11 21 19 6 23 9 14

How would I use ifstream,and argv from the command line to push the values into a stack?

Did research and using this as help, but it may not be relevant:

How to push data of different data types into a vector by reading from a file?

Community
  • 1
  • 1
Rohit Tigga
  • 2,373
  • 9
  • 43
  • 81

1 Answers1

1

Here is something to get you started.

stack<int> data;
{
    ifstream file("file.txt");
    int i;
    while (file >> i)
    {
        data.push_back(i);
    }
}
Neil Kirk
  • 21,327
  • 9
  • 53
  • 91