quotation marks in string

i need help with inserting double quotation marks for string .
when i enter movie name . the movie name needs to show up in quotation marks. such as
"Death Grip".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;


int main()
{

    string movieName;
    int noOfAdultTicketSold;
    int noOfChildTicketSold;
    const double AdultTicFee = 6;
    const double ChildTicFee = 3;




    cout <<setw(29)<< left << "Movie Name:""\"" <<movieName<<"\""<</r;
  getline(cin,movieName);
 
  
Hello!

A very good way to get the movie name surrounded by quotation marks, you can use quoted, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using std::cout;

#include <iomanip>
using std::quoted;
using std::left;
using std::setw;

#include <string>
using std::string;

int main()
{
	string movieName = "Vaganova Ballet Academy - The Nutcracker Performance";

	cout << setw(29) << left << "Movie Name: " << quoted(movieName) << std::endl;

	return 0;
}


To get an output, you have to change your code. First comes the input, then the output. ;-)

1
2
 getline(cin, movieName);
 cout << setw(29) << left << "Movie Name: " << quoted(movieName) << std::endl;


It would also be good to initialize your variables with a value, else it can lead to unexpected and sometimes incorrect results.

1
2
3
4
5
    string movieName = " ";
    int noOfAdultTicketSold = 0;
    int noOfChildTicketSold = 0;
    const double AdultTicFee = 6.0;
    const double ChildTicFee = 3.0;
Last edited on
Topic archived. No new replies allowed.