DancingFighterG
asked on
Question on printing out a line
Hello, I'm trying to print out one line at time from a file once it each reaches a part of my progam. This is what I have right now!
while(lexreturn != 41)
{
getline(inFile, line);
cout << "\n" << endl;
cout << line << endl;
lexreturn = lex();
}
What is happenning is that it will reach this while loop while it's not end of file and I want it to print out a line at time. For example, if the file looked like this;
PROGRAM aProgramName();
number : Real;
The output would be this:
PROGRAM aProgramName(); <- this is what i want
PROGRAM [program] ,-This is not important for this problem
etc....
number : Real; <- this is what i want
etc... -This is not important for this problem
How would I go about doing this? I hope that I am making this clear!
while(lexreturn != 41)
{
getline(inFile, line);
cout << "\n" << endl;
cout << line << endl;
lexreturn = lex();
}
What is happenning is that it will reach this while loop while it's not end of file and I want it to print out a line at time. For example, if the file looked like this;
PROGRAM aProgramName();
number : Real;
The output would be this:
PROGRAM aProgramName(); <- this is what i want
PROGRAM [program] ,-This is not important for this problem
etc....
number : Real; <- this is what i want
etc... -This is not important for this problem
How would I go about doing this? I hope that I am making this clear!
Just move your getline logic into the while condition.
Why are you using lex()??
What is this function suppose to do?
If it's an extra condition that you need, you can use both together.
Example:
while(lexreturn != 41 && getline(inFile, line))
{
cout << "\n" << endl;
cout << line << endl;
lexreturn = lex();
}
Why are you using lex()??
What is this function suppose to do?
If it's an extra condition that you need, you can use both together.
Example:
while(lexreturn != 41 && getline(inFile, line))
{
cout << "\n" << endl;
cout << line << endl;
lexreturn = lex();
}
ASKER
For some reason getline is printing the line but it's clearing all the other data that I need after it. Is there another method that can be used to print a line of a file read to screen.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, well how my program works is that it's reading a file reading in each individual character. I'm putting these characters in a buffer. What I trying to do is after each \n print the source line. This is what I have:
void readInput()
{
if(bufferA[0] = '\n')
{
getline(inFile, line);
cout << line << endl;
}
bufferA[0] = inFile.peek();
if(inFile.eof())
{
bufferA[0] = '\0';
}
current_character = bufferA[0];
current_character_class = getCharacterClass(current_ character) ;
}
I want the output to look like this:
VAR
VAR [var]
but right now it just prints out VAR and moves to the next line.
void readInput()
{
if(bufferA[0] = '\n')
{
getline(inFile, line);
cout << line << endl;
}
bufferA[0] = inFile.peek();
if(inFile.eof())
{
bufferA[0] = '\0';
}
current_character = bufferA[0];
current_character_class = getCharacterClass(current_
}
I want the output to look like this:
VAR
VAR [var]
but right now it just prints out VAR and moves to the next line.
{
cout << "\n" << endl;
cout << line << endl;
}