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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:51:43+00:00 2026-05-30T22:51:43+00:00

While trying my code to answer another question I found out that the following

  • 0

While trying my code to answer another question I found out that the following didn’t compile

#include <iostream>
#include <cstring>
#include <sstream>
#include <string>

using namespace std;

// (main omitted)
const char * coin = "3D";
istringstream ss(string(s));
int i;
ss >> hex >> i;              <--- error here
cout << (char) i << endl;

It failed with the following error:

test.cpp:15:11: error: invalid operands of types ‘std::istringstream(std::string) {aka std::basic_istringstream<char>(std::basic_string<char>)}’ and ‘std::ios_base&(std::ios_base&)’ to binary ‘operator>>’

While the following compiled and ran properly :

const char* coin = "3D";
string s(coin);
istringstream ss(s); // or directly istringstream ss("3D")
int i;
ss >> hex >> i;              
cout << (char) i << endl;

If I look at the definition of the constructor of istringstream, it accepts const std::string& (actually the basic_string<char> equivalent), and that compiles. So I guess the template argument deduction has a behaviour I don’t understand and create a not so conform istringstream, but why ?

I am using GCC 4.6.1 (Ubuntu flavor).

EDIT : since istringstream is a typedef, I doubt there’s any problem with templates in the end.

  • 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-30T22:51:44+00:00Added an answer on May 30, 2026 at 10:51 pm
    istringstream ss(string(s));
    

    Your compiler thinks that’s a declaration of a function taking a string (named s) and returning an istringstream. Surround the argument in parentheses in order to disambiguate it. By the way, what is s? Did you mean coin there?

    istringstream ss( (string(coin)) );
    

    Read this if you are confused.

    In this particular case, you could of course have just done this:

    istringstream ss(coin);
    

    If your compiler supports it, you can also avoid the MVP using uniform initialization syntax:

    istringstream ss{string{coin}};
    

    That probably looks a bit odd to most people, I know it looks odd to me, but that’s just because I’m so used to the old syntax.

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

Sidebar

Related Questions

While trying to answer this question I found that the code int* p =
While trying to answer another question, I was serializing a C# object to an
This question is a result of what i noticed while trying to answer another
While trying to answer a question in the vicinity ' Unit Testing WPF Bindings
Recently while trying to answer a questions here, I ran some test code to
I got an error today while trying to do some formatting to existing code.
I am getting an error while trying to run CFmx code on a remote
I keep getting this error while trying to modify some tables. Here's my code:
I am trying to learn and writting this part of code. while testing few
While trying to connect to a database that's set to read only, the connection

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.