Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Handling a double click Pin
Jader892-Mar-06 10:09
Jader892-Mar-06 10:09 
GeneralRe: Handling a double click Pin
David Crow2-Mar-06 10:33
David Crow2-Mar-06 10:33 
GeneralRe: Handling a double click Pin
Jader892-Mar-06 10:47
Jader892-Mar-06 10:47 
GeneralRe: Handling a double click Pin
David Crow2-Mar-06 10:58
David Crow2-Mar-06 10:58 
Questionloop processing Pin
ronwurster2-Mar-06 9:51
ronwurster2-Mar-06 9:51 
AnswerRe: loop processing Pin
David Crow2-Mar-06 9:53
David Crow2-Mar-06 9:53 
GeneralRe: loop processing Pin
ronwurster3-Mar-06 4:33
ronwurster3-Mar-06 4:33 
Questiongetline from file Pin
Peter Charlesworth2-Mar-06 9:34
Peter Charlesworth2-Mar-06 9:34 
hi everyone!

I have a question regarding input and output with files (standard C/C++).
Whenever I use the 'getline' function to get a line from a file and then ask the
program to display that line, it always displays more than a line.
In other words: it doesn't stop 'getting the line' whenever it encounters a
newline.
How can I make sure he reads only one line and no more?
And how can I tell the program to get a specific line, like line n° 34
or the line that follows the words 'myline:' or whatever?

Thanks in advance!

Peter


The program that's supposed to get one line but gets more then that is this one:

<br />
#include <iostream><br />
#include <fstream><br />
#include <string><br />
using namespace std;<br />
<br />
int main () {<br />
  string line;                      // declare a string named 'line'<br />
  ifstream myfile ("example.txt");<br />
  if (myfile.is_open())             // if the file is open, then...<br />
  {<br />
    while (! myfile.eof() )         // while the end of the file is NOT reached...<br />
    {<br />
      getline (myfile,line);        // get a line from the file and put it in the string 'line'<br />
      cout << line << endl;         // output the contents of 'line' to the screen<br />
    }<br />
    myfile.close();                 // close the file   <br />
  }<br />
<br />
  else cout << "Unable to open file";    // if the file can't be opened, display "Unable to open file<br />
<br />
  return 0;                         // close the program<br />
}<br />
<br />

AnswerRe: getline from file Pin
David Crow2-Mar-06 9:52
David Crow2-Mar-06 9:52 
GeneralRe: getline from file Pin
Peter Charlesworth2-Mar-06 9:57
Peter Charlesworth2-Mar-06 9:57 
GeneralRe: getline from file Pin
David Crow2-Mar-06 10:05
David Crow2-Mar-06 10:05 
GeneralRe: getline from file Pin
Peter Charlesworth3-Mar-06 3:01
Peter Charlesworth3-Mar-06 3:01 
Questionembedded VC and activesync problem Pin
neodan2-Mar-06 9:27
neodan2-Mar-06 9:27 
AnswerRe: embedded VC and activesync problem Pin
Mauro Leggieri2-Mar-06 16:11
Mauro Leggieri2-Mar-06 16:11 
GeneralRe: embedded VC and activesync problem Pin
neodan2-Mar-06 21:15
neodan2-Mar-06 21:15 
Questioninteger/ character Pin
cuteee2-Mar-06 7:20
cuteee2-Mar-06 7:20 
AnswerRe: integer/ character Pin
David Crow2-Mar-06 7:51
David Crow2-Mar-06 7:51 
QuestionRe: integer/ character Pin
cuteee2-Mar-06 8:07
cuteee2-Mar-06 8:07 
AnswerRe: integer/ character Pin
David Crow2-Mar-06 8:24
David Crow2-Mar-06 8:24 
QuestionCalling .exe withing project. Pin
CodeGoose2-Mar-06 6:59
CodeGoose2-Mar-06 6:59 
AnswerRe: Calling .exe withing project. Pin
Brett Peirce2-Mar-06 7:10
Brett Peirce2-Mar-06 7:10 
AnswerRe: Calling .exe withing project. Pin
David Crow2-Mar-06 7:47
David Crow2-Mar-06 7:47 
Questionhelp plz Pin
mechalien2-Mar-06 6:43
mechalien2-Mar-06 6:43 
AnswerRe: help plz Pin
Maximilien2-Mar-06 6:52
Maximilien2-Mar-06 6:52 
AnswerRe: help plz Pin
Peter Charlesworth2-Mar-06 9:40
Peter Charlesworth2-Mar-06 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.