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 6529197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:36:28+00:00 2026-05-25T09:36:28+00:00

I have an MFC source file that I need to compile under Qt. This

  • 0

I have an MFC source file that I need to compile under Qt. This file uses MFC/ATL CString. Specifically it uses a CString as an argument to iostream::open(). I have written a CString class that inherits from QString so that I can use most of QStrings’ functionality.

My main concern is that I cannot get my CString implementation to work where iostream::open() is called:

Here is a bit of my class declaration:

    class CString : public QString {
    public:
        CString() : QString() {}
        CString(const QString& other) : QString(other) {}
        CString(const CString& other) : QString(other) {}
        CString(_In_opt_z_ const XCHAR* pszSrc) : QString( pszSrc ) { *this = pszSrc; }
        CString(const char* pszSrc) : QString( pszSrc ) {}
        ...
    }

And, here is a portion of code to use the CString:

ofstream outfile;
CString Path("dump.txt");

outfile.open(Path);

The error is:

no matching function for call to ‘std::basic_ofstream >::open(CString&)’

Under ‘normal’ circumstances, I would simply do something like:

outfile.open(Path.toStdString().c_str());

However, that is not an option. No modification of the original code is authorized. 🙁

Is there a way to do this, or am I going to have to rebuild the class using the same, rather more complex and lengthy code, that Microsoft uses in cstringt.h?

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-05-25T09:36:29+00:00Added an answer on May 25, 2026 at 9:36 am

    Define a typecast operator for your CString class as follows:

    operator const char*() { return this->toStdString().c_str(); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MFC sdi app that uses a splitter window to contain a
I have an MFC application that I was given (without source code) which opens
I have an MFC application that uses an ancient (circa 1999) third-party ActiveX control.
I have a non-MFC, non-ATL C++ app that routinely creates notification balloons on a
Okay basically I have an MFC application with lots of dialogs that need to
I have an MFC legacy app that I help to maintain. I'm not quite
I have a MFC dialog with 32 CComboBoxes on it that all have the
We have a MFC 8 application compiled with /CLR that contains a larger amount
I have a C++/MFC application I need to restructure. The app used to process
I have an MFC application that spawns a number of different worker threads and

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.