String gets split into separate strings

This program is supposed to accept a string and convert all lowercase letters to uppercase and then print them. The problem is that if i enter a sentence like
"Hello World". The output gets split into two different lines. The whole program works perfectly except that. Why is that happening?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <conio.h>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
void show (string strs);

int main ()
{
  string output;


do 
{
cout << "Enter a string(q to quit): ";
cin >> output;
show(output);

}
while (output != "q");


getch();
return 0;

}
 
 
void show (string strs)
{
     int i;
     for (i = 0; i < strs.size(); i++)
     strs[i] = toupper(strs[i]); 
     
     cout << strs << endl;   
}
cin >> output;

This only gets one word at a time. Use getline() instead.

Also, remove conio.h/getch(), use cin.get() instead.
Thank you very much. It works now.
Topic archived. No new replies allowed.