Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:50:58+00:00 2026-06-18T06:50:58+00:00

I am developing an MFC application using Visual C++ 2010 I am reading data

  • 0

I am developing an MFC application using Visual C++ 2010

I am reading data for one file but It seems seekg is not working

Here is my code

//Transaction is a class i have defined before

void displayMessage(CString message)
{
    MessageBox(NULL,message,L"error",MB_OK | MB_ICONERROR);
}

///////////////////////////////
    ifstream input;

    input.open("test.dat" , ios::binary );
    if( input.fail() )
    {
        CString mess;
        mess = strerror( errno );
        mess.Insert(0,L"Error\n");
        displayMessage(mess);
    }

    Transaction myTr(0,myDate,L"",0,0,L""); // creating an object of transaction
    unsigned long position = 0;
    while(input.read( (char *) &myTr , sizeof(Transaction)))
    {
        if(myTr.getType() == 400 )
            position = (unsigned long)input.tellg() - sizeof(Transaction);
    }


    CString m;
    m.Format(L"Pos : %d",position);
    displayMessage(m);

    input.clear();//I also tried removing this line
    input.seekg(position,ios::beg );

    m.Format(L"get pos: %d",input.tellg());
    displayMessage(m);
    input.close();

The first displayMessage shows This : Pos : 6716 But second one showes : get pos: 0

Why seekg is not working ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:51:00+00:00Added an answer on June 18, 2026 at 6:51 am

    The problem is that CString.Format() is a varargs function and basic_istream::tellg() returns a pos_type which isn’t a type that can be passed as a vararg agument so you get undefined behavior.

    If you want to pass the position you get bace from tellg() to CString::Format() you’ll need to cast it or put it in a temporary, intermediate variable:

        unsigned long new_pos = input.tellg();
        m.Format(L"get pos: %d", new_pos);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an AutoCad plugin (MFC dll), I'm using Visual Studio 2010 and C++.
I'm developing an interactive MFC application which displays a 3D object using my own
I am developing an MFC application. I am working with my own .bmp image
I am in process of developing an MFC based Windows based application, using PostgreSQL
I am developing a Windows API application without using MFC . I am using
I have experience developing MFC applications with C++ using Visual Studio 6.0. You can
I am developing MFC Dialog based application in Visual Studio 2008. I want to
I am developing windows CE 6.0 for VIA board. I have a MFC application
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
While developing an application using gwt in ecliplse crashed. Now the server is running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.