C++

main.cc
#include <iostream>
#include <sstream>
#include <stdint.h>
 
#if 1
std::ostream & operator<<
(
  std::ostream & p_ostream ,
  char const   * p_object
)
{
  if (p_object)
  {
    p_ostream << std::string(p_object);
  }
  return(p_ostream);
}
#endif
#if 1
std::ostream & operator<<
(
  std::ostream      & p_ostream ,
  signed char const * p_object
)
{
  return(p_ostream << (char const *)p_object);
}
#endif
#if 1
std::ostream & operator<<
(
  std::ostream        & p_ostream ,
  unsigned char const * p_object
)
{
  return(p_ostream << (char const *)p_object);
}
#endif
 
template <class T>
void test_function
(
  std::ostream & p_ostream
)
{
  {
    T * tmp = 0;
    p_ostream.clear();
    p_ostream << tmp << std::endl;
    std::cerr << std::string("stream state: ") << (p_ostream.good() ? std::string("OK") : std::string("NOK")) << std::endl;
  }
  {
    T * const tmp = 0;
    p_ostream.clear();
    p_ostream << tmp << std::endl;
    std::cerr << std::string("stream state: ") << (p_ostream.good() ? std::string("OK") : std::string("NOK")) << std::endl;
  }
}
 
int main()
{
  test_function < char          > ( std::cout ); //OK
  test_function < char const    > ( std::cout );
  test_function < int8_t        > ( std::cout );
  test_function < int8_t const  > ( std::cout );
  test_function < uint8_t       > ( std::cout );
  test_function < uint8_t const > ( std::cout );
 
  std::stringstream oss;
  test_function < char          > ( oss );
  test_function < char const    > ( oss );
  test_function < int8_t        > ( oss );
  test_function < int8_t const  > ( oss );
  test_function < uint8_t       > ( oss );
  test_function < uint8_t const > ( oss );
 
  return( 0 );
}

@TaG: CPlusPlus StreaM

iostream.txt · Last modified: 2022/04/16 12:23 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki