Неверное преобразование из ‘const char *’ в ‘char’

В настоящее время я работаю над разной программой театральных расселений! Я только начинаю прогрессировать через C ++, но я не могу понять эту ошибку, которую я продолжаю получать в своем коде. То, что я сейчас пытаюсь закодировать, это способ ввода символа «*» за символом, в конечном счете, чтобы помочь мне построить функцию для отображения графика рассадки для кинотеатра. Я довольно близок к завершению функции readSeating … Хотя с этим есть некоторые явные проблемы. Обычно я могу довольно эффективно отлаживать свои программы, но я просто не могу понять это. Пожалуйста, посмотрите на мой код, почувствуйте мою программу и дайте мне какие-нибудь идеи. Пожалуйста, держите ответы несколько простыми; опять же, я не мастер в C ++

Постскриптум

Извините за показ всего кода … Это мой первый пост … Я не знал, что включить, а что нет; и я хотел, чтобы люди могли почувствовать программу, даже протестировав ее сами … Еще раз спасибо!

/*
* This is a program built by a team of students
* to help local movie theaters sell tickets
*
* File: main.cpp
* Author(s):
*
*
* Created on April 15, 2013, 11:10 AM
*/#include <cstdlib>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cctype>
#include <iomanip>

using namespace std;

//Function Prototypes
void Title_Card();
void seating_prices();
void seating_chart();
void pick_seating();
void purchase_history();
void quit();
void update_file();
void Show_Menu();
void is_digit(int&);
void Admin_Menu();
void edit_seating_prices();
void edit_seating();
void quit_to_original();
void purchase_history_admin();

int readSeating (char, vector<char>&); //Reads SeatingChart.txt
int readPrices(string, vector<double>&); //Reads SeatingPrices.txt
vector<double> prices(15); //For SeatPrices.txt
vector<char> seating(450); //For SeatingChart.txt//Actual Program
int main() {
Title_Card(); //Calls Title Page

readSeating("SeatingChart.txt", seating); //Reads SeatingChart.txt
readPrices("SeatPrices.txt", prices); //Reads SeatPrices.txt
Show_Menu(); //Shows Introductory Menu

system ("pause");
return 0;
}//**************************************************************
// Definition of the ShowMenu function. Shows introductory menu*
// and controls where user ends up in the program.             *
//**************************************************************void Show_Menu() {
int choice;
string password;

cout << "Welcome to the our theater program! Made for a person" << endl;
cout << "who is looking for seating, purchasing a ticket, and" << endl;
cout << "searching for other miscellaneous things... We hope" << endl;
cout << "you enjoy the program!" << endl << endl;
cout << "Below is a list of options the user can choose from:" << endl << endl;
cout << "1.\tSeating Prices" << endl;
cout << "2.\tPick Seating" << endl;
cout << "3.\tPurchase History" << endl;
cout << "4.\tQuit" << endl << endl;
cout << "Enter a choice... (1-4): ";
cin >> choice;

//Secret Administrator Access
if (choice == 219){
system ("cls");
cout << "Enter the administrator password: ";
cin >> password;

if (password == "sterilegorilla")
Admin_Menu();
else {
system ("cls");
Show_Menu();
}
}

is_digit(choice);//is_digit function doesn't work atmwhile (choice < 1 || choice > 4){
cout << endl << "You have entered an invalid choice!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> choice;
is_digit(choice); //is_digit function doesn't work atm
if (choice == 219){
system ("cls");
cout << "Enter the administrator password: ";
cin >> password;

if (password == "sterilegorilla")
Admin_Menu();

else {
system ("cls");
Show_Menu();
}
}
}

switch (choice) {
case 1:
seating_prices();

case 2:
pick_seating();

case 3:
purchase_history();

case 4:
quit();
}

}
//**************************************************************
// Definition of the seating_prices function. Displays to the  *
// user, SeatPrices.txt                                        *
//**************************************************************void seating_prices(){
system ("cls");
cout << "The Current Seating Prices Are:" << endl << endl;
for (int count = 0; count < 4; count++){
cout << " " << setprecision(4) << showpoint <<  prices[count] << " | Row " << (count + 1) <<                         endl;
}
for (int count = 4; count < prices.size(); count++){
cout << "  " << setprecision(3) << showpoint <<  prices[count] << " | Row " << (count + 1) << endl;
}
cout << endl;
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the pick_seating function. Displays the       *
// current seating chart and allows the user to pick their seat*
//**************************************************************void pick_seating(){  //Not Finished
system ("cls");
int row_choice;
int seat_choice;

cout << "The Current Seating Chart Is:" << endl;

//Display Seating Chart//Picking your seat
cout << "Enter the row number you would like to be in (1-15): ";
cin >> row_choice;
while (row_choice < 1 || row_choice > 15){
cout << endl << "You have entered an invalid row number!" << endl;
cout << "Enter the row number you would like to be in (1-15): ";
cin >> row_choice;
}

cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
while (seat_choice < 1 || seat_choice > 30){
cout << endl << "You have entered an invalid seat number!" << endl;
cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
}

cout << "Congratulations! You have picked your seat!" << endl << endl;
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the purchase_history function. Displays the   *
// current the total sum of all movie ticket purchases         *
//**************************************************************void purchase_history(){         //Not finished
system ("cls");
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the quit function. Allows the user to quit the*
// program entirely                                            *
//**************************************************************void quit(){
update_file();
exit(0);
}//**************************************************************
// Definition of the is_digit function. Designed to make it    *
// possible to enter only integers when asked for integers     *
//**************************************************************void is_digit(int & input){      //Not working atm
if (isdigit(input)){
return;
}
if (isalpha(input)){
cout << endl << "You have entered an invalid data type!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> input;
}
if (isspace(input)){
cout << endl << "You have entered an invalid data type!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> input;
}
}//**************************************************************
// Definition of the update_file function. Designed to update  *
// the seating chart upon leaving the pick_seating function    *
//**************************************************************void update_file(){  //Not finished

//This function is supposed to
//Update the seating chart
//upon exit of the pick_seating function
}//**************************************************************
// Definition of the Admin_Menu function. Displays the         *
// administrator-based menu if user knows the code and password*
//**************************************************************void Admin_Menu(){

system ("cls");
int choice = 0;

cout << "Hello! This is the administrator version";
cout << endl << "of the theatre program; mainly used for editing purposes." << endl << endl;
cout << "Below is a list of options the administrator can choose from:" << endl << endl;
cout << "1.\tEdit Seating Prices" << endl;
cout << "2.\tEdit Seating" << endl;
cout << "3.\tPurchase History" << endl;
cout << "4.\tQuit to Original" << endl;
cout << "5.\tQuit Program" << endl << endl;
cout << "Enter a choice... (1-5): ";
cin >> choice;

while (choice < 1 || choice > 5){
cout << endl << "You have entered an invalid choice!" << endl;
cout << "Enter a choice... (1-5): ";
cin >> choice;
}

switch (choice) {
case 1:
edit_seating_prices();

case 2:
edit_seating();

case 3:
purchase_history_admin();

case 4:
quit_to_original();

case 5:
quit();
}
}//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the seating chart                          *
//**************************************************************void edit_seating(){             //Not finished
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the prices of the seats.                   *
// This will in turn, overwrite SeatPrices.txt                 *
//**************************************************************void edit_seating_prices(){    //Not finished
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the purchase_history_admin function.          *
// Administrator-only function designed to show admin the      *
// total sum of ticket sales... NOT EDITABLE                   *
//**************************************************************void purchase_history_admin(){
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the quit_to_original function. Administrator- *
// only function designed to return admin to original program  *
//**************************************************************void quit_to_original(){
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the read_file function. Reads SeatPrices.txt  *
// and stores the pre-determined prices into a vector named    *
// prices.                                                     *
//**************************************************************int readPrices(string myFile, vector<double>& vect) {

//input file
ifstream SeatPrices;

SeatPrices.open(myFile.c_str());//if file cannot be found
if (!SeatPrices)
cout << "Cannot find the file!" << endl;for (int index = 0; index < vect.size(); index++){
SeatPrices >> vect[index];   //Reading the file "SeatPrices.txt"}

SeatPrices.close();  //Closes the file
return 0;
}//**************************************************************
// Definition of the readSeating function. Reads a text file   *
// with a seating chart in it.                                 *
//**************************************************************int readSeating(char myFile, vector<char>& vect){           //Not EVEN CLOSE TO FINISHING//input file
ifstream SeatingChart;
SeatingChart.open(myFile);

//if file cannot be found
if (!SeatingChart)
cout << "Cannot find the file!" << endl;

for (int index = 0; index < vect.size(); index++){
SeatingChart >> vect[index];  //Reading the file "SeatingChart.txt"}

SeatingChart.close(); //Closes the file
return 0;
}//**************************************************************
// Definition of the Title_Card function. Starts the program   *
// with a title card, showing a little introductory title      *
//**************************************************************void Title_Card(){
cout << endl << endl << endl << endl;
cout << "\t\t" << "************************************************\n";
cout << "\t\t" << "*               THEATER SEATING!               *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*     A program created by a team of three     *\n";
cout << "\t\t" << "*     students to help small theaters sell     *\n";
cout << "\t\t" << "*                 more tickets                 *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*              Team of Students:               *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*                *************                 *\n";
cout << "\t\t" << "*                 ***********                  *\n";
cout << "\t\t" << "*                *************                 *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "************************************************\n";
cout << endl << endl;
system ("pause");
system ("cls");
}

1

Решение

Прежде всего (Я думаю, это то, что вы намеревались написать)

int readSeating (char, vector<char>&);

должно быть

int readSeating (char*, vector<char>&);
^^^

ожидать lvalue за первый аргумент. То, что это означает, это просто то, что он может назначить.

Однако вы называете это как

readSeating("SeatingChart.txt", seating);

передавая временное значение для первого аргумента. Компилятор хочет знать, что вы не будете изменять его, чтобы позволить вам пройти временный. Вы можете сказать ему, что не измените его, объявив функцию как.

int readSeating (const char*, vector<char>&);
^^^^

То же самое касается

int readSeating(char myFile, vector<char>& vect)

в

int readSeating(const char* myFile, vector<char>& vect)

Я предлагаю вам пойти дальше и изменить их на strings,

int readSeating (string, vector<char>&);
int readSeating(string myFile, vector<char>& vect)
2

Другие решения

Исправил это для вас. Строковый литерал (например, «somestring») имеет тип «char const *». Это не может рассматриваться как символ.

/*
* This is a program built by a team of students
* to help local movie theaters sell tickets
*
* File: main.cpp
* Author(s):
*
*
* Created on April 15, 2013, 11:10 AM
*/#include <cstdlib>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <cctype>
#include <iomanip>

using namespace std;

//Function Prototypes
void Title_Card();
void seating_prices();
void seating_chart();
void pick_seating();
void purchase_history();
void quit();
void update_file();
void Show_Menu();
void is_digit(int&);
void Admin_Menu();
void edit_seating_prices();
void edit_seating();
void quit_to_original();
void purchase_history_admin();

int readSeating (const char*, vector<char>&); //Reads SeatingChart.txt
int readPrices(string, vector<double>&); //Reads SeatingPrices.txt
vector<double> prices(15); //For SeatPrices.txt
vector<char> seating(450); //For SeatingChart.txt//Actual Program
int main() {
Title_Card(); //Calls Title Page

readSeating("SeatingChart.txt", seating); //Reads SeatingChart.txt
readPrices("SeatPrices.txt", prices); //Reads SeatPrices.txt
Show_Menu(); //Shows Introductory Menu

system ("pause");
return 0;
}//**************************************************************
// Definition of the ShowMenu function. Shows introductory menu*
// and controls where user ends up in the program.             *
//**************************************************************void Show_Menu() {
int choice;
string password;

cout << "Welcome to the our theater program! Made for a person" << endl;
cout << "who is looking for seating, purchasing a ticket, and" << endl;
cout << "searching for other miscellaneous things... We hope" << endl;
cout << "you enjoy the program!" << endl << endl;
cout << "Below is a list of options the user can choose from:" << endl << endl;
cout << "1.\tSeating Prices" << endl;
cout << "2.\tPick Seating" << endl;
cout << "3.\tPurchase History" << endl;
cout << "4.\tQuit" << endl << endl;
cout << "Enter a choice... (1-4): ";
cin >> choice;

//Secret Administrator Access
if (choice == 219){
system ("cls");
cout << "Enter the administrator password: ";
cin >> password;

if (password == "sterilegorilla")
Admin_Menu();
else {
system ("cls");
Show_Menu();
}
}

is_digit(choice);//is_digit function doesn't work atmwhile (choice < 1 || choice > 4){
cout << endl << "You have entered an invalid choice!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> choice;
is_digit(choice); //is_digit function doesn't work atm
if (choice == 219){
system ("cls");
cout << "Enter the administrator password: ";
cin >> password;

if (password == "sterilegorilla")
Admin_Menu();

else {
system ("cls");
Show_Menu();
}
}
}

switch (choice) {
case 1:
seating_prices();

case 2:
pick_seating();

case 3:
purchase_history();

case 4:
quit();
}

}
//**************************************************************
// Definition of the seating_prices function. Displays to the  *
// user, SeatPrices.txt                                        *
//**************************************************************void seating_prices(){
system ("cls");
cout << "The Current Seating Prices Are:" << endl << endl;
for (int count = 0; count < 4; count++){
cout << " " << setprecision(4) << showpoint <<  prices[count] << " | Row " << (count + 1) <<                         endl;
}
for (int count = 4; count < prices.size(); count++){
cout << "  " << setprecision(3) << showpoint <<  prices[count] << " | Row " << (count + 1) << endl;
}
cout << endl;
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the pick_seating function. Displays the       *
// current seating chart and allows the user to pick their seat*
//**************************************************************void pick_seating(){  //Not Finished
system ("cls");
int row_choice;
int seat_choice;

cout << "The Current Seating Chart Is:" << endl;

//Display Seating Chart//Picking your seat
cout << "Enter the row number you would like to be in (1-15): ";
cin >> row_choice;
while (row_choice < 1 || row_choice > 15){
cout << endl << "You have entered an invalid row number!" << endl;
cout << "Enter the row number you would like to be in (1-15): ";
cin >> row_choice;
}

cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
while (seat_choice < 1 || seat_choice > 30){
cout << endl << "You have entered an invalid seat number!" << endl;
cout << "Enter the seat number you would like to have (1-30): ";
cin >> seat_choice;
}

cout << "Congratulations! You have picked your seat!" << endl << endl;
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the purchase_history function. Displays the   *
// current the total sum of all movie ticket purchases         *
//**************************************************************void purchase_history(){         //Not finished
system ("cls");
system ("pause");
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the quit function. Allows the user to quit the*
// program entirely                                            *
//**************************************************************void quit(){
update_file();
exit(0);
}//**************************************************************
// Definition of the is_digit function. Designed to make it    *
// possible to enter only integers when asked for integers     *
//**************************************************************void is_digit(int & input){      //Not working atm
if (isdigit(input)){
return;
}
if (isalpha(input)){
cout << endl << "You have entered an invalid data type!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> input;
}
if (isspace(input)){
cout << endl << "You have entered an invalid data type!" << endl;
cout << "Enter a choice... (1-4): ";
cin >> input;
}
}//**************************************************************
// Definition of the update_file function. Designed to update  *
// the seating chart upon leaving the pick_seating function    *
//**************************************************************void update_file(){  //Not finished

//This function is supposed to
//Update the seating chart
//upon exit of the pick_seating function
}//**************************************************************
// Definition of the Admin_Menu function. Displays the         *
// administrator-based menu if user knows the code and password*
//**************************************************************void Admin_Menu(){

system ("cls");
int choice = 0;

cout << "Hello! This is the administrator version";
cout << endl << "of the theatre program; mainly used for editing purposes." << endl << endl;
cout << "Below is a list of options the administrator can choose from:" << endl << endl;
cout << "1.\tEdit Seating Prices" << endl;
cout << "2.\tEdit Seating" << endl;
cout << "3.\tPurchase History" << endl;
cout << "4.\tQuit to Original" << endl;
cout << "5.\tQuit Program" << endl << endl;
cout << "Enter a choice... (1-5): ";
cin >> choice;

while (choice < 1 || choice > 5){
cout << endl << "You have entered an invalid choice!" << endl;
cout << "Enter a choice... (1-5): ";
cin >> choice;
}

switch (choice) {
case 1:
edit_seating_prices();

case 2:
edit_seating();

case 3:
purchase_history_admin();

case 4:
quit_to_original();

case 5:
quit();
}
}//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the seating chart                          *
//**************************************************************void edit_seating(){             //Not finished
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the edit_seating function. Administrator-only *
// function to edit the prices of the seats.                   *
// This will in turn, overwrite SeatPrices.txt                 *
//**************************************************************void edit_seating_prices(){    //Not finished
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the purchase_history_admin function.          *
// Administrator-only function designed to show admin the      *
// total sum of ticket sales... NOT EDITABLE                   *
//**************************************************************void purchase_history_admin(){
system ("cls");
system ("pause");
system ("cls");
Admin_Menu();
}//**************************************************************
// Definition of the quit_to_original function. Administrator- *
// only function designed to return admin to original program  *
//**************************************************************void quit_to_original(){
system ("cls");
Show_Menu();
}//**************************************************************
// Definition of the read_file function. Reads SeatPrices.txt  *
// and stores the pre-determined prices into a vector named    *
// prices.                                                     *
//**************************************************************int readPrices(string myFile, vector<double>& vect) {

//input file
ifstream SeatPrices;

SeatPrices.open(myFile.c_str());//if file cannot be found
if (!SeatPrices)
cout << "Cannot find the file!" << endl;for (int index = 0; index < vect.size(); index++){
SeatPrices >> vect[index];   //Reading the file "SeatPrices.txt"}

SeatPrices.close();  //Closes the file
return 0;
}//**************************************************************
// Definition of the readSeating function. Reads a text file   *
// with a seating chart in it.                                 *
//**************************************************************int readSeating(const char* myFile, vector<char>& vect){           //Not EVEN CLOSE TO FINISHING//input file
ifstream SeatingChart;
SeatingChart.open(myFile);

//if file cannot be found
if (!SeatingChart)
cout << "Cannot find the file!" << endl;

for (int index = 0; index < vect.size(); index++){
SeatingChart >> vect[index];  //Reading the file "SeatingChart.txt"}

SeatingChart.close(); //Closes the file
return 0;
}//**************************************************************
// Definition of the Title_Card function. Starts the program   *
// with a title card, showing a little introductory title      *
//**************************************************************void Title_Card(){
cout << endl << endl << endl << endl;
cout << "\t\t" << "************************************************\n";
cout << "\t\t" << "*               THEATER SEATING!               *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*     A program created by a team of three     *\n";
cout << "\t\t" << "*     students to help small theaters sell     *\n";
cout << "\t\t" << "*                 more tickets                 *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*              Team of Students:               *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "*                *************                 *\n";
cout << "\t\t" << "*                 ***********                  *\n";
cout << "\t\t" << "*                *************                 *\n";
cout << "\t\t" << "*                                              *\n";
cout << "\t\t" << "************************************************\n";
cout << endl << endl;
system ("pause");
system ("cls");
}
1