Solved

Question on printing out a line

Posted on 2004-09-22
8
165 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

777 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