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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:54:03+00:00 2026-06-07T19:54:03+00:00

This the below program i have written for some test. class tgsetmap { public:

  • 0

This the below program i have written for some test.

class tgsetmap
{
public:
std::map<std::string,std::string> tgsetlist;
void operator<<(const char *str1,const char *str2)
{
  tgsetlist.insert( std::map<std::string,std::string>::value_type(str1,str2));
}

};


int main()
{

tgsetmap obj;

obj<<("tgset10","mystring");

obj.tgsetlist.size();
}

This throws a compilation error:

“test.cc”, line 10: Error: Illegal number of arguments for tgsetmap::operator<<(const char, const char*).
“test.cc”, line 22: Error: The operation “tgsetmap << const char*” is illegal.
2 Error(s) detected.*

Am i wrong some where?

  • 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-07T19:54:04+00:00Added an answer on June 7, 2026 at 7:54 pm

    You can’t force operator<< to take two arguments on right-hand side. The following code:

    obj<<("tgset10","mystring");
    

    does not work as a function call with two arguments but instead just uses the , operator. But it’s probably not what you are interested in.

    If you need to pass two arguments to the << operator, you need to wrap them in some other (single) type. For example, you could use the standard std::pair, i.e. std::pair<const char*, const char*>.

    But note that the operator<< should also return some reasonable type suitable for << chaining. That would probably be a tgsetmap& in your case. The following version should work fine:

    #include <map>
    #include <string>
    #include <iostream>
    
    class tgsetmap
    {
    public:
        typedef std::map<std::string, std::string> list_type;
        typedef list_type::value_type item_type;
    
        list_type tgsetlist;
    
        tgsetmap& operator<<(item_type item)
        {
            tgsetlist.insert(item);
            return *this;
        }
    };
    
    int main()
    {
        tgsetmap obj;
    
        obj << tgsetmap::item_type("tgset10","mystring")
            << tgsetmap::item_type("tgset20","anotherstring");
    
        std::cout << obj.tgsetlist.size() << std::endl;
    }
    

    Note that I’ve added typedefs to not have to repeat the type names over and over again. I’ve also made operator<< return a tgsetmap& so that << could be chained (used like in the modified main() above). And finally, I’ve reused the std::map<...>::value_type to make it simpler but you could also use any other type of your own.


    But I believe that you may prefer using a regular method instead. Something like:

    void add(const char *str1, const char *str2)
    {
        tgsetlist.insert( std::map<std::string, std::string>::value_type(str1, str2));
    }
    

    (inside the class declaration), and then:

    obj.add("tgset10", "mystring");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I have the below program written in C++: #include <iostream> using namespace std; int
I have written a sample program below. class Program { static int x =
Given below is program for encrypting a string. I had taken this code from
Below is a program i have written that ran fine when I type what
I have written a small program: void showrecord() { char *a[]={ O_BILLABLE_ACCOUNT,O_CUSTOMER_TYPE_INDICATOR, O_A_PARTY_MSISDN_ID,O_A_PARTY_EQUIPMENT_NUMBER, O_A_PARTY_IMSI,O_A_PARTY_LOCATION_INFO_CELL_ID,
I have a problem with some strings created by a sequence alignment program (this
In this below program i am printing the contents of the div when i
This program below moves the last (junior) and the penultimate bytes variable i type
This code below doesn't work correctly since my MFC program is in unicode circumstance.

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.