Question
I have this piece of c++ code ifstream myFile; myFile.open(argv[2]); while(true){//repeat while we will not reach till end of file char ch; myFile>>ch; if (myFile.eof())
I have this piece of c++ code
ifstream myFile; myFile.open(argv[2]); while(true){//repeat while we will not reach till end of file char ch; myFile>>ch; if (myFile.eof()) break; switch(ch){ case '+':cout<<"PLUS"< case '-':cout<<"MINUS"< case '*':cout<<"STAR"< case '/':cout<<"SLASH"< case '(':cout<<"LPAREN"< case ')':cout<<"RPAREN"< case ';':cout<<"SC"< case '=':cout<<"ASSIGN"< case '>':cout<<"GT"< case '<':cout<<"LT"< case ' ':break;
it reads a file that contains this < > * ( ) ; / / - +
LT
GT
STAR
LPAREN
RPAREN
SC
SLASH
SLASH
MINUS
PLUS
but now i need help with this if the file has this < > * ( ) ; / / - + "hello" + - the output would be
LT
GT
STAR
LPAREN
RPAREN
SC
SLASH
SLASH
MINUS
PLUS
SCONST (hello)
PLUS
MINUS
If this is is in the file, > * ( ) ; / - + "hello how are you " +
GT
STAR
LPAREN
RPAREN
SC
SLASH
MINUS
PLUS
SCONST (hello how are you)
PLUS
so basically when see a " in the file print out SCONST along with the string that was in it till the closing " so if the file has this "*-*-*"
it would print
SCONST (*-*-*)
i feel like adding a case '"': would be helpful please show the correct outputs to see that the code actaully works
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started