How do you let the line of text end with something other than \n?

I am trying to write a function for a console app which will allow the user to enter in text using carriage returns and end the line upon input of a period (.). I, for the life of me, cannot figure it out.


I would like to overload the following function for ease of use:

1
2
3
4
5
6
7
8
9
10
inline void get_line(string & s)
{
    cout.flush();
    if (cin.peek() == '\n')
    {
        cin.ignore(); 
    }
    getline(cin, s);
    return;
}
Anyone? =]
std::getline() can get an additional parameter, which is a delimiter char (default is '\n')
http://cplusplus.com/reference/string/getline/
Em...
http://www.fedoraforum.org/forum/showthread.php?page=1&t=147415
http://en.wikipedia.org/wiki/Ncurses

EDIT: @Romai:
I think he wants to read back from the buffered input upon pressing the period key.

-Albatross
Last edited on
Wait, this sounds suspicious.
What exactly are you trying to accomplish with this? Perhaps we can suggest a better way.
Why is that suspicious? He wants to get the input buffer when '.' is pressed instead of '\n'. What's suspicious about that?

@OP,
That means you'll need to use raw mode. Use pdcurses or ncurses.

pdcurses: http://pdcurses.sourceforge.net/
ncurses: http://www.gnu.org/software/ncurses/
It is suspicious because he is asking a question that might be better answered using a different mode of thought than what you assume he is trying to do.
@Duoas: That's why we didn't give him the answer obtained by that mode of thought.

-Albatross
Because I want to first know what he is thinking, rather than make wild stabs at random possibilities.
I recognize your concerns Duoas, but I do believe that Ncurses couldn't be used to record keystrokes when the program using its library is not selected.

-Albatross
Well it could, in the same way system() could be used to delete system files. Just because it could be used for that, it doesn't mean it will.

Edit:

Or are we just going to operate under a "guilty until proven innocent" policy?
Last edited on
Topic archived. No new replies allowed.