trapping control character in getline

This is a discussion on trapping control character in getline within the C++ Programming forums, part of the General Programming Boards category; I have a text input system that recognises and includes white spaces, however for formatting reasons i want to include ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    trapping control character in getline

    I have a text input system that recognises and includes white spaces, however for formatting reasons i want to include the option to inlclude a new line and it still to be recognised as the same array.

    My code is as follows
    //includes
    //setup etc
    char TextString[256];
    cin.getline(TextString, 256);


    this works and gets the string with spaces but i want the users to be able to add a new line - pressing enter enters the text. I am stuck, please help
    tia
    Monday - what a way to spend a seventh of your life

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    istream::getline takes three parameters, the third of which is the delimeter. By default it is '\n' so istream::getline returns when it encounters a getline. Change this to whatever you want your delimeter to be to have it end then:
    Code:
    char TextString[256];
    cin.getline(TextString, 256, 'x'); // Stores any characters from cin in TextString until an 'x' is encountered.
    - lmov

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  2. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  3. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 05:32 PM
  4. Updating a list control
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2003, 02:03 AM

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