Inputting spaces from cin?

I am working on a movie rater program and in it I ask the user to input movie titles. Cin does not allow the user to type in spaces if the movie has a space in it. For example, "The Hulk" will be typed in as "TheHulk". I am trying to implement a function that will break up the string at the capital letters and insert a space. So if the input is "IHaveADream" I want the program to return "I Have A Dream". You may assume the first letter is a caps (and even if not you will still get a reasonable result; so "badNews" should still return "bad News"). The function is called string breakStringAtCaps(string in);. I'm thinking I need to use the isupper function somewhere. Any ideas on how I can implement this function to my program?
How would I implement that code wise? I've never used that
How would I implement that code wise?

instead of
 
    cin >> movie_title;

you would have
 
    getline(cin, movie_title);

It needs to be in a function
You need to provide more information. Show your own code.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* By implementing this correctly and integrating it into your
 * project so that movie names are displayed with spaces, even
 * though the user enters them without spaces you can earn
 * some additional extra credit.
 * 
 * Breaks up a string at capital letters and inserts spaces 
 * So if the input is "IHaveADream" return "I Have A Dream".
 * You may assume the first letter is a caps (and even if it
 * not you will still get a reasonable result; so "badNews" 
 * should still return "bad News").
 *
 * Parameters:
 *  in:  string with no spaces
 *
 * Return a version of the string with spaces
 */
string breakStringAtCaps(string in);

string breakStringAtCaps(string in)
{
  /* !!!!!!!! Implement this for extra credit if you desire !!!!! */
  /* Otherwise leave this as is  
  */
  return in;

}


/**********************************************************
 *  Main must be completed by you.
 **********************************************************/
int main()
{
  const int SIZE = 20;
  string movies[SIZE];
  int ratings[SIZE];
  int numMovies = 0;
  string name;
  int rating;
  int selection;
  
  //do while loop will execute while the selection the user inputs is in between 1 and 4
  do
  {
    int selection = printPromptAndGetInput();
    
    if(selection == 1)
    {
      cout << "Enter movie name and rating"<<endl;
      cin >> name;
      cin >> rating;
      insertMovie(movies, ratings, name, rating, numMovies);
      numMovies++;
      
    }
    else if(selection == 2)
    {
      cout << "Enter the movie name and the updated rating" << endl;
      rateMovie(movies, ratings, name, rating, numMovies);
      
    }
    else if(selection == 3)
    {
      cout << "Enter the name of the movie you wish to delete" << endl;
      deleteMovie(movies, ratings, name, numMovies);
      numMovies--;
      
    }
    else if(selection == 4)
    {
      sortList(movies, ratings, numMovies);
      printList(movies, ratings, numMovies);
    }
  }while(selection >= 1 || selection < 5);


  return 0;
}


Trying to implement the string breakStringAtCaps(string in) function
One way to do this is to use a for-loop to examine each character in the string. If it is an upper-case letter, then insert a space at that position.

To find the length of the string: size()
To test for upper case: isupper()
To insert a space: insert()

The insert is easy enough, but a word on that. The string insert function allows several different possibilities, though we want to insert only a single character, use the syntax " " which really is a string containing a single space. Also, add 1 to the loop counter afterwards or you might test the same character again on the next iteration of the loop.
1
2
    in.insert(i, " ");
    ++i;


http://www.cplusplus.com/reference/string/string/size/
http://www.cplusplus.com/reference/cctype/isupper/
http://www.cplusplus.com/reference/string/string/insert/
Topic archived. No new replies allowed.