Thread: Smart way of defining an end of operator<<

  1. #1
    Registered User bremenpl's Avatar
    Join Date
    Apr 2013
    Posts
    57

    Smart way of defining an end of operator<<

    Hello there,
    Before I desribe the problem, I would just like to say that I am struggling with it all day basicaly and also that I am not very expirienced with c++ language.

    So I am trying to write a singleton multithreaded logger application using standard libraries in c++. Using various tutorials and provided help i almost succed. The last thing I cannot do is auto new line. For example when using cout, if you want new line character you need to add std::endl or '\n':
    Code:
    std::cout << "some text" << std::endl;
    But when for example using the qDebug() method (Qt) you dont need that, the new line character is added automatically. SO the cout code would e the same as:
    Code:
    qDebug() << "some text";
    I really want the second functionality. So I have posted a similar question os Stack Overflow where an user got me the general idea of what to do, but I am having problem with the implementation. Here is the post: c++ - How to define an end of operator<< method? - Stack Overflow

    Mu current way of doing new line is searching for the '\n' line every time the opearator<< is used which is unsufficient and the end of line sign can be forgotten easily.
    Before any changes, my code looked and worked like this:
    main.c
    CLogger.h
    CLogger.cpp

    Now here i tried to apply the changes. Everything compiles but I get an error message when running the first method:
    Code:
    terminate called after throwing an instance of 'std::out_of_range'
      what():  basic_string::erase
    Here is the code:
    main.c
    CLogger.h
    CLogger.cpp

    I dont know either this suggested method is the best, but the only one I know about so far.
    I would really, really apriciate help in this topic. It means a lot to me to get this working. If there is any more information needed I will provide it asap.
    Last edited by bremenpl; 06-26-2015 at 02:41 PM.

  2. #2
    Registered User bremenpl's Avatar
    Join Date
    Apr 2013
    Posts
    57
    Anyone please?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart Tic Tac Toe!!
    By xcoverdalex in forum Game Programming
    Replies: 7
    Last Post: 08-27-2010, 11:30 AM
  2. Very smart compiler?
    By 39ster in forum C++ Programming
    Replies: 5
    Last Post: 01-09-2008, 06:46 AM
  3. Need help plz help if your smart
    By cplusplus12 in forum C++ Programming
    Replies: 0
    Last Post: 02-21-2006, 05:58 PM
  4. Should I be smart about the types I use?
    By Kleid-0 in forum C Programming
    Replies: 4
    Last Post: 11-20-2005, 02:45 AM
  5. defining objects in a non-member operator?
    By pkananen in forum C++ Programming
    Replies: 5
    Last Post: 12-13-2001, 12:17 PM

Tags for this Thread