?
Solved

Question on printing out a line

Posted on 2004-09-22
8
Medium Priority
?
169 Views
Last Modified: 2010-04-01
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!


0
Comment
Question by:DancingFighterG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 12127408
while(getline(inFile, line))
    {
                    cout << "\n" << endl;
        cout << line << endl;
  }
0
 
LVL 30

Expert Comment

by:Axter
ID: 12127428
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();
 }
0
 

Author Comment

by:DancingFighterG
ID: 12129854
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.
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 12130162
>>For some reason getline is printing the line but it's clearing all the other data that I need after it.

How do you know it's clearing all the other data?

Please post more of your code.
0
 

Author Comment

by:DancingFighterG
ID: 12133792
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question