First letter keeps getting cut off in my string output??

I can't seem to figure out why the first letter of my strings is getting cut off when it is displayed. I tried doing things like cin.ignore and cin.clear in different places and nothing worked. I tried looking it up and someone said something about a carriage return but I don't really know what that is.

Can anyone help me??

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
 #include <iostream>
#include <string>
#include <climits>

using namespace std;

// Write the structure declaration to hold the movie information.
struct MovieInfo
{
	string movieName;
	string director;
	int releaseYear;
	
	MovieInfo(string m = "unknown", string d = "unknown")
	{
		movieName = m;
		director = d;
		
		if (releaseYear < 1889 || releaseYear > 2025)
		{
			cout << "You have entered an invalid year." << endl;
		}
	}
};

int main(void)
{
	string favMovie;
	string favMdirector;
	int yearReleased;
	
	// Define the structure variable here.
	MovieInfo movie;

	cout << "Enter the following information about your "
		 << " favorite movie.\n" << "Name: ";
	
	// Write a statement here that lets the user enter a movie name.
	// Store it in the appropriate structure member.
//	cin.clear();
	
//	cin.ignore(INT_MAX, '\n');
	cin.get();
	getline(cin, favMovie);
	movie.movieName = favMovie;
	cin.clear();
	
	cout << "Director: ";
	
	// Write a statement here that lets the user enter the director's
	// name. Store it in the appropriate structure member.
//	cin.clear();
	
//	cin.ignore(INT_MAX, '\n');
	cin.get();
	getline(cin, favMdirector);
	movie.director = favMdirector;
	
	cout << "Year of Release: ";
	
	// Write a statement here that lets the user enter the movie
	// release year. Store it in the appropriate structure member.
	cin >> yearReleased;
	movie.releaseYear = yearReleased;
	
	cout << "\nHere is information on your favorite movie:\n";
	
	// Write statements here that display the information
	// just entered into the structure variable.
	cout << "My favorite movie is " << movie.movieName << ", the director was " << movie.director
		 << " and it was released in " << movie.releaseYear << "." << endl;
	
	return 0;
}
I would advise you to move the if statement inside the constructor to your main. The reason behind that is because constructors, when called, will print automatically whatever is inside(meaning it will always bypass your if statement). You use constructors(usually) to initialize private members with default values; not to print things.
Thank you for the great advice! It makes a lot of sense and I didn't even realize it haha But is there any chance you know the solution to my original question?
I think it's fixed now try this.

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
#include <iostream>
#include <string>
#include <climits>

using namespace std;


struct MovieInfo
{
	string movieName;
	string director;
	int releaseYear;
	
	MovieInfo(string m = " ", string d = " ")
	{
		movieName = m;
		director = d;
	}
};

int main(void)
{
	string favMovie;
	string favMdirector;
	int yearReleased;
	
	MovieInfo movie;

	cout << "Enter the following information about your "
		 << "favorite movie.\n" << "\nName: ";

	getline(cin, favMovie);
	movie.movieName = favMovie;
	
	cout << "Director: ";
	
	getline(cin, favMdirector);
	movie.director = favMdirector;
	
	cout << "Year of Release: ";
	cin >> yearReleased;
	
	if (yearReleased < 1889 || yearReleased > 2025)
		{
			cout << "You have entered an invalid year." << endl;
			cin >> yearReleased;
		}
	
	movie.releaseYear = yearReleased;
	
	
	cout << "\nHere is information on your favorite movie:\n";
	
	cout << "My favorite movie is " << movie.movieName << ", the director was " << movie.director
		 << " and it was released in " << movie.releaseYear << "." << endl;
	
	return 0;
}
Oh! I just shouldn't have used the .get(). Thank you so much!
You're welcome :)
Topic archived. No new replies allowed.