Thread: anouther easy probeblem...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    anouther easy probeblem...

    I am making a

    Code:
    cin.getline(word_1, 50, 'I_want_a_space_here')
    I know that \n means an enter. But what is the "code" thing for a space?


    Update: Ok now I am guessing I am looking like an idoit, and just puting a space shoudl work right?
    Last edited by Rune Hunter; 09-15-2004 at 04:48 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    First of all, they are called "escape sequences", not "code" thing, lol. The \n means newline. As for an escape sequence for a single space, I can't recall there being one, if I am wrong, I am sure someone will correct me on this. If you want to do a tab, you can use \t.

    Look up the escape sequences in your help files or try doing a google search on C++ escape sequences. I did just to make sure I was right about there not being one for single spaces and it looks like I am most likely correct, but take a look for yourself.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    well I am prettys rue there is one sence just a ' ' doesn't work. I have to hit enter if I put that in there.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    hmmm...well if i had my laptop i could take a look, but it is at work so i am a little stuck here.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    oh wait...instead of using ' around your string, try " instead.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    didn't work.

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Space is 0x20 ( hex ) as far as its ascii value is concerned.
    What is C++?

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    Well, I am sorry I couldn't be of help, without my laptop, I am powerless.

  9. #9
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    The space ' ' works fine. You expect it to stop letting you type after the space, but that is not how standard input works. It will let you type until you hit Enter, then it will only read the first word up until a space into word_1. This program outputs only the first word if you type in several words separated by a space.
    Code:
    #include <iostream>
    
    int main()
    {
    	char word_1[50];
    	std::cin.getline(word_1, 50, ' ');
    	std::cout << word_1 << std::endl;
    }

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    std::cin.getline ( word_1, 50, 0x20);

    Will take all input until enter is pressed... but only put whatever is before the first space into word_1.

    using \t you can keep typing until you hit tab.

    [edit]
    std::cin.getline ( word_1, 50, '\x20');

    If you want to use an escape sequence.
    Last edited by Vicious; 09-15-2004 at 05:20 PM.
    What is C++?

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy String position question...
    By Striph in forum C Programming
    Replies: 4
    Last Post: 05-11-2009, 08:48 PM
  2. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  3. anouther probeblem about strings...
    By Rune Hunter in forum C++ Programming
    Replies: 12
    Last Post: 09-21-2004, 09:11 PM
  4. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  5. Replies: 20
    Last Post: 05-25-2002, 07:14 PM