How to use Getline?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yasaminkh
    New Member
    • Jun 2010
    • 2

    How to use Getline?

    I'm working with a file. I want to write a code that returns a particular string located somewhere in the file. I have the starting position of the desired string and it's length so I thought that i can use getline. but i'm not sure how to do that.For using get line can i use the position of the pointer of the file as first argument?

    I know that getline needs a pointer to an array of characters and the number of characters as input. I'm not familiar with the concept of pointer that much and i 'm not sure if the position of the pointer is equivalent to the pointer itself. Can anybody help me with this please.
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    getline only reads to the end of the current line (that is, until it encounters a newline character). Notice that the terminating newline is discarded.

    Can the string you are searching for span multiple lines?

    Comment

    • yasaminkh
      New Member
      • Jun 2010
      • 2

      #3
      Thanks for the quick answer. Yes it's just a single line. Actually I'm working with an xml file. somewhere in my file i have a line like this:
      <ERROR converged="yes" method="jackkni fe">1.31e-05</ERROR>

      and i want to store the number in that line in a string, and i know the starting position and the length of the number. Can I use getline to put that number in a string, by writing something like:

      num_as_str =getline(start+ 12, end-start+13);

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        I hesitate to break donbock`s train of thought but I think you can use atof() on that string and it will return the floating point number but only as a number not as a string.

        Comment

        Working...