Solved

Question on printing out a line

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need 'Configuration File' Management Library for C++ Project 1 487
mixing C++ & C# in Vis Studio 2013 7 141
Unable to start eclipse ? 17 129
Problem with SqlConnection 4 159
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

15 Experts available now in Live!

Get 1:1 Help Now