0

Hey, i just start working with string and i am totally noob =). So i would like to ask you if you can help me... I have some programs to write, but i have a little problems to get the code working...

Ok first question is, how do i make a program, that will ask a user to input 10 lines of text.

void lines(string lines)
{
   for (int i=0; i<10; i++)
   {
      cout<<"Line "<<i+1<<": ";
      getline(cin, lines);
      cout<<endl;
       
   }

    
}

I wrote it like this. With this code i could write 10 lines of text, but the line here ends when i press enter(running in cmd). I would like that the lines will count, not when i press enter, but when the text goes in new line(because it is at the end of the cmd window). Is this possible?

I hope you understad what i ment =)

ps
----------
sry for my bad english =)

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by HASHMI007
0

That's not possible. Why? One reason is that getline() doesn't know, or care, what the size of the command window is. It reads everything up to the '\n', or some other character you specify.

-2
#include<iostream.h>
#include<conio.h>
void lines(char );
void lines(char string_lines[100])
{
for (int i=0; i<10; i++)
    {

cout<<"Line "<<i+1<<": ";
cin>> string_lines;

}

}
void main()
{
char string_lines[100];

lines(string_lines);

}

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.