Solved

Question on printing out a line

Posted on 2004-09-22
8
163 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
  • 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 50 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now