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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:44:41+00:00 2026-05-25T00:44:41+00:00

I am well aware of techniques to convert CString to a C-style character. One

  • 0

I am well aware of techniques to convert CString to a C-style character. One of them is to use strcpy/_tcscpy, and others include using CStrBuf.

The problem:

char Destination[100];
CStringA Source; // A is for simplicity and explicit ANSI specification.

Source = "This is source string."

Now I want this:

Destination = Source;

To happen automatically. Well, that logically means writing a conversion operator in CString class. But, as implicit as it is, I dont have privileges to change the CString class.

I thought of writing a global conversion opertor and global assignment operator. But it doesnt work:

operator char* (const CStringA&); // Error - At least must be class-type
operator = ... // Won't work either - cannot be global.

Yes, it is definitely possible to write function (preferably a templated one). But that involves calling the function, and it is not smooth as assignment operator.

  • 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-25T00:44:42+00:00Added an answer on May 25, 2026 at 12:44 am

    Well, I don’t want to say that this is in any way recommendable, but you could hijack some lesser-used operator for a quick hack:

    void operator<<=(char * dst, const std::string & s)
    {
      std::strcpy(dst, s.c_str());
    }
    
    int main()
    {
      char buf[100];
      std::string s = "Hello";
    
      buf <<= s;
    }
    

    You could even rig up a moderately safe templated version for statically sized arrays:

    template <typename TChar, unsigned int N>
    inline void operator<<=(TChar (&dst)[N], const std::string & s)
    {
      std::strncpy(dst, s.c_str(), N);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm well aware of using namespaces however, every now and then I'm stumbling upon
I'm well aware of the technique of using URL fragments to track state on
I'm well aware of how I can communicate with an outside server using Android.
I’m well aware of the Microsoft support base article stating that it’s not supported
While I am well aware that it isn't possible for me to refer to
Disclaimer I am well aware that PHP might not have been the best choice
Let me preface this by saying that I'm well aware that running user supplied
I'm well aware of how to get files from the client to the server
In a project of mine one common use case keeps coming up. At some
Edit: I'm well aware of that this works very well with value types, my

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.