Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have read in a file successfully to a queue.. I have a sample.txt file that op

ID: 3663053 • Letter: I

Question

I have read in a file successfully to a queue..

I have a sample.txt file that opens and it says this :

This part is the beginning. {This part is the footnote.} This part is the end.

I want it to only read the stuff inside the {}'s . This is the code I have so far:

#include <iostream>

#include <fstream>

using namespace std;

#include "Queue.h"

int main()

{

   Queue q1;

   char c;

   char fname;

ifstream file;

//File.open("sample.txt");

   cout<<"Enter filename:";

   cin>>file;

//ifstream in(fname);

   file.open("sample.txt");

   if(!file)

   {

       cout<<"File Does Not Exist";

   }

   while(!file.eof())

   {

       file.get(c);

       if (c == '{')

       {

       q1.enqueue(c);

       cout<<c;

       }

       if (c == '}')

       {

          

       }

   }

   file.close();

It reads the file in successfully, but how do I get it to start at one curly brace and end at the other. Also, what if there were two {{ or }} ?? I became a bit stuck on that part in my if statements. I am using c++ 98.. any insight would be helpful!

Explanation / Answer

if(c=={)

{

if(c==})

{

exit the loop

}

q1.enqueue(c);

cout<<c;

}