Textinput with more than one line

J

Jean Pierre Hort

Hi,
I am going to write a kind of editor for Linux.
It is one of my first projects so I'm not having much experience.

It work's very good, I can chose a filename, if this file exists text
will be written at the end of this file, if it does not exist this file
will be created.

My problem now is, I get the text of the user which should be written
into the file via "cin >> var". This var will then be written into the
file. But, I can only do one line, when I press enter for making a new
line the text will be send to the cin.
Is there an easy way to put a text with more than one line into a
stringvariable? So that I can press enter more than one time for
creating numerous endls? The input should be ended when entering EOF or
something like that.

Is there an easy way realising that?

Regards
 
J

John Harrison

Jean said:
Hi,
I am going to write a kind of editor for Linux.
It is one of my first projects so I'm not having much experience.

It work's very good, I can chose a filename, if this file exists text
will be written at the end of this file, if it does not exist this file
will be created.

My problem now is, I get the text of the user which should be written
into the file via "cin >> var". This var will then be written into the
file. But, I can only do one line, when I press enter for making a new
line the text will be send to the cin.
Is there an easy way to put a text with more than one line into a
stringvariable? So that I can press enter more than one time for
creating numerous endls? The input should be ended when entering EOF or
something like that.

Is there an easy way realising that?

Regards

If you what to get input until EOF then just read one character at a
time until EOF and append each char to the string.

string text;
char ch;
while (cin.get(ch))
text += ch;

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top