Thread: How to Convert Space in ascii?

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    1

    How to Convert Space in ascii?

    I have a problem with converting the Space char into other chars.
    I'm working in a program with the objective of simulate a encoder machine, so when i have to encode the space char to other char(by adding a Int key to their original ascii code), the cin operator doesn't recognize the Space char.
    How can I encode/decode the space char using this method?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    There is no cin operator. cin is an object--not an operator. Perhaps you mean the operator>>, which is known as the insertion operator. The insertion operator is defined so that it does not read in spaces. I'm not sure what that has to do with encoding characters, but there you have it.

    If you need to read in multiple words from cin, then you can use the form of getline() appropriate to the type of your input variable.
    Last edited by 7stud; 11-28-2005 at 06:47 AM.

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Quote Originally Posted by Ancient Dragon
    cin>>filename does not accept spaces in the filename. If the path contains spaces then use getline()

    When filename is std::string
    Code:
    std::string filename
    getline(cin,filename);
    when filename is character array
    Code:
    char  filename[255];
    cin.getline(filename,sizeof(filename));
    And you don't need cin.ignore() after inputting strings. That will cause the program to stop and wait for more user input!
    Using get line will keep the spaces in there. Hope this helps.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by 7stud
    Perhaps you mean the operator>>, which is known as the insertion operator.
    >> is the stream extraction operator, << is the stream insertion operator.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    lol. Hey, it inserts it into the variable!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read space from the file
    By Ken JS in forum C++ Programming
    Replies: 9
    Last Post: 08-05-2007, 03:13 AM
  2. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  5. Convert Char to Int Function
    By drdroid in forum C++ Programming
    Replies: 9
    Last Post: 02-19-2003, 12:53 PM