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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:16:18+00:00 2026-05-31T00:16:18+00:00

This is my custom string class (xstring.hpp): #include <vector> #include <sstream> namespace { using

  • 0

This is my custom string class (xstring.hpp):

#include <vector>
#include <sstream>

namespace
{
    using std::vector;
    using std::istringstream;

    template <class strT>
    class xstring_base
    {
        private:
            strT str;

        public:
            operator strT&() {return str;}
            vector<strT>* tokenize();

            // constructors
            xstring_base<strT>(strT);
    };
}
#include "xstring.cpp"

#include <string>
typedef xstring_base<std::string> xstring;

I’ve put the operator strT&() to mimic the Standard Library’s string behavior wherever needed, and this class works absolutely fine when I initialize it with a C-style string, even containing non-ASCII code, for example arabic, but std::getline complains that xstring is not supported.

How can I use getline to input from cin to this custom string class of mine?

(I use g++ on Kubuntu 11.10. Gives tens of lines of complain about template mixture mismatches…)

Thanks so much!

  • 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-31T00:16:19+00:00Added an answer on May 31, 2026 at 12:16 am

    std::getline is a function template that looks like this:

    template< class CharT, class Traits, class Allocator >
    std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>& input,
                                               std::basic_string<CharT,Traits,Allocator>& str );
    

    When you call std::getline(std::cin, x), you don’t provide template arguments. This means that the types will have to be deduced from the arguments.

    However, the type deduction algorithm does not take user-defined conversions into account. So your conversion operator is not used. If you wrote std::getline<char, std::char_traits<char>, std::allocator<char>>(std::cin, x), no type deduction is needed, so the conversion operator would be considered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with a custom indexer like so public string this[VehicleProperty property]
I am leaking memory on this: my custom class: + (id)vectorWithX:(float)dimx Y:(float)dimy{ return [[[Vector
I have homework that I need to make a custom string class using C
I wonder if the flash.utils.getDefinitionByName(name:String):Class works with custom classes? Is there a problem if
When writing a custom string class that stores UTF-8 internally (to save memory) rather
I have this custom wpf user control: ShowCustomer.xaml: <UserControl x:Class=TestControlUpdate2343.Controls.ShowCustomer xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid> <TextBlock
Consider this class: class foo(object): pass The default string representation looks something like this:
I'm trying to write this custom addition class for very large integers, bigger than
First, please look at this custom Button-inherited UserControl code: Public Class UserControl1 Dim _Text
I understand that inheriting from std::string class is a poor idea, but was just

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.