Strange Results from cout

This is a discussion on Strange Results from cout within the C++ Programming forums, part of the General Programming Boards category; Is there any reason that this: Code: std::cout << "PRIVMSG " << CHANNEL << "a" << std::endl; should ever output ...

  1. #1
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229

    Strange Results from cout

    Is there any reason that this:
    Code:
    std::cout << "PRIVMSG " << CHANNEL << "a" << std::endl;
    should ever output this:
    Code:
    aRIVMSG #test
    Where CHANNEL does equal #test.

    I'm doing some socket programming, but I didn't think this is related to network programming.

    Maybe it is something to do with byte order? Also if I just output CHANNEL by it's self, it works properly.

    I'm stumped.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Is CHANNEL a regular std::string?

  3. #3
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Yes, sorry, I forgot to mention that.

    EDIT: I fixed it...Gosh, I always do this. As soon as I give up and ask for help, I figure it out. Anyway, it was because there was some strange character at the end of CHANNEL, I cut it off and it works fine now.
    Last edited by IdioticCreation; 11-24-2007 at 08:53 PM.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Quote Originally Posted by IdioticCreation View Post
    Is there any reason that this:
    Code:
    std::cout << "PRIVMSG " << CHANNEL << "a" << std::endl;
    should ever output this:
    Code:
    aRIVMSG #test
    Start removing parts of that line until it stops failing. For instance, if you take the "a" part out, does it still fail? What if you remove CHANNEL? Etc. Whittle it down until it doesn't fail anymore then report your results.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Interesting. Possibly a char that has to do with right-to-left text.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Nope, it was a carriage return. Did you read channel from a file that was created in Windows, on Unix.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Actually I read it out of a socket. It was an IRC connection. I am on Unix, I don't know about the server that's hosting the IRC.

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Quote Originally Posted by IdioticCreation View Post
    Actually I read it out of a socket. It was an IRC connection. I am on Unix, I don't know about the server that's hosting the IRC.
    Maybe you read a '\r' character. This warps the cursor to the beginning of the line. Then it prints 'a'. Why there would be a '\r' in a channel name? No clue.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Probably because the IRC spec says so:
    RC messages are always lines of characters terminated with a CR-LF (Carriage Return - Line Feed) pair
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 72hour GDC Results
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-05-2004, 11:46 PM
  2. strange numbers, while loops questionable?
    By exluddite in forum C++ Programming
    Replies: 8
    Last Post: 05-06-2004, 11:11 AM
  3. Getting bizarre results from simple math
    By mmyers1 in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2004, 06:39 PM
  4. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM
  5. FAQ cout
    By evilmonkey in forum FAQ Board
    Replies: 1
    Last Post: 10-07-2001, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21