?
Solved

Question on printing out a line

Posted on 2004-09-22
8
Medium Priority
?
172 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
5 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…
Suggested Courses

864 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