CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    18

    Get Address of Line (Reading Files)

    If I'm reading a text file line by line, how do I get the byte address of the start of each line?

  2. #2
    Join Date
    Oct 2011
    Posts
    97

    Re: Get Address of Line (Reading Files)

    That depends, how are you reading the lines in? I'm assuming you're using C++, so if you have a string or CString, you can just use &variableName.

  3. #3
    Join Date
    Sep 2010
    Posts
    18

    Re: Get Address of Line (Reading Files)

    I'm using string class.

    ifstream file;
    name = 'text.txt';

    file.open(name.data());
    while(getline(file, lnstr))
    {
    cout << file.seekg();
    }

    This is what I was doing, but it keeps spitting out the same number. I want to spit it out line by line what the address is. On another note I'm trying to show it as byte values, specifically in 8bytes.
    Last edited by Howdy_McGee; April 16th, 2012 at 11:50 PM.

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,507

    Re: Get Address of Line (Reading Files)

    1) use tellg() not seekg()

    2) care should be taken when using seekg/tellg using VC++ if the file is opened
    in text mode.

    3) it is still not clear to me why you need that information

  5. #5
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+)
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    7,888

    Re: Get Address of Line (Reading Files)

    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #6
    GCDEF is offline Elite Member Power Poster GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+)
    Join Date
    Nov 2003
    Posts
    11,563

    Re: Get Address of Line (Reading Files)

    What do you mean by "address", the offset from the start of the file? Just count the length of each line, making sure to account for the new line characters.

    What do you mean by 8byte?

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width