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

  • Home
  • SEARCH
  • 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 6939463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:37:32+00:00 2026-05-27T12:37:32+00:00

I had to write a function which binary_print(outstream& outs,unsigned int a) but when i

  • 0

I had to write a function which binary_print(outstream& outs,unsigned int a)
but when i write a test file for that function it says error.

#include<iostream>

int main()
{ 
    unsigned int d;
    std::cout<<"Enter any positive decimal number:";
    std::cin>>d;
         std::cout<<"Binary of your number is "<<binary_print(cout,d);//<<endl;

     std::cout<<'\n';}
}

errors:

testfile_rec.cpp:18:60: error: no match for ‘operator<<‘ in
‘std::operator<< [with _Traits =
std::char_traits](((std::basic_ostream&)(& std::cout)),
((const char*)”Binary of your number is “)) <<
binary_print(((std::ostream&)(& std::cout)), d)’ ostream:108:7: note:
candidates are: std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT, Traits>::_ostream_type& (*)(std::basic_ostream<_CharT, Traits>::_ostream_type&)) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:117:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, Traits>::_ios_type& (*)(std::basic_ostream<_CharT, Traits>::_ios_type&)) [with _CharT =
char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream, std::basic_ostream<_CharT, Traits>::_ios_type =
std::basic_ios] ostream:127:7: note:
std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base&
(*)(std::ios_base&)) [with _CharT = char, _Traits =
std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:165:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:169:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:173:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>&
std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with
_CharT = char, _Traits = std::char_traits] ostream:180:7: note: std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int)
[with _CharT = char, _Traits = std::char_traits,
std::basic_ostream<_CharT, Traits>::_ostream_type =
std::basic_ostream] ostream.tcc:105:5: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits] ostream:191:7: note:
std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with
_CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT, Traits>::_ostream_type =
std::basic_ostream] ostream:200:7: note:
std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with
_CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT, Traits>::_ostream_type =
std::basic_ostream] ostream:204:7: note:
std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned
int) [with _CharT = char, _Traits = std::char_traits,
std::basic_ostream<_CharT, Traits>::_ostream_type =
std::basic_ostream] ostream:209:7: note:
std::basic_ostream<_CharT, Traits>::_ostream_type&
std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT =
char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:213:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:221:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream:225:7: note: std::basic_ostream<_CharT,
Traits>::_ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_ostream_type = std::basic_ostream] ostream.tcc:119:5: note: std::basic_ostream<_CharT,
_Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, Traits>::_streambuf_type*) [with _CharT = char, _Traits = std::char_traits, std::basic_ostream<_CharT,
Traits>::_streambuf_type = std::basic_streambuf]

  • 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-27T12:37:33+00:00Added an answer on May 27, 2026 at 12:37 pm

    If you want to print the binary representation of the given integer, then easy way is to use std::bitset as:

    #include<bitset> //include this so as to use std::bitset
    
    unsigned int input;
    std::cin >> input;
    std::cout << std::bitset<32>(input) << std::endl;
    

    This will print 32-bit binary representation of the value stored in input. It is even better to write this as:

    #include <bitset>   //for std::bitset
    #include <climits>  //for CHAR_BIT
    
    std::cout << std::bitset<CHAR_BIT * sizeof(input)>(input) << std::endl;
    

    Now you can wrap this functionality in a function as:

    template<typename T>
    void binary_print(std::ostream & out, const T & input)
    { 
       out << std::bitset<CHAR_BIT * sizeof(T)>(input) << std::endl;
    }
    

    Test code:

    int main() {
            int input;
            std::cin >> input;
            binary_print(std::cout, input);        //print int-representation
            binary_print(std::cout, (short)input); //print short-representation
            return 0;
    }
    

    Output:

    00000000000000000010001000010100
    0010001000010100
    

    Online demo : http://ideone.com/OQU6F

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

Sidebar

Related Questions

I'm trying to write a very simple function which displays a div that says
I have some code that I had to write to replace a function that
I've had problem when trying write a function which has a default value when
I've had quite a bit of trouble trying to write a function that checks
I'm doing K&R Exercise 5-4 (p107). Write the function strend(s,t) , which returns 1
I've just had to write a string reverse function in C# 2.0 (i.e. LINQ
I have experience with OCaml. You had to write a stub for every function
If you had to write code that takes messages from a message queue and
Suppose I only had the regular J2SE http libraries but wanted to write a
I am trying to write a program in PHP which I had already written

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.