Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:38:55+00:00 2026-05-24T12:38:55+00:00

I get the following errors with my code. cannot convert parameter 1 from ‘std::string’

  • 0

I get the following errors with my code.

cannot convert parameter 1 from ‘std::string’ to ‘char *

no operator found which takes a right-hand operand of type ‘const char *

Can someone tell me what I’m doing wrong in the menuSelection function below? The point of it is if a user selects 1 from the menu options, the program gets user input (lastName, firstName, courseName, letterGrade) and passes it to the addRecord function but I think my data types are off.

Sorry for the long post. The menuSelection function is towards the bottom right about the main() and head() functions.

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

   
void GradeBook::addRecord(char* lastName, char* firstName, char* className, char letterGrade)
{
    StudentRecord* newRecord = new StudentRecord(lastName, firstName, className, letterGrade);
    if (_headRecord == NULL) {
        _headRecord = newRecord;
    } else { 
        int compare = _headRecord->compareTo(lastName, firstName);
        if (compare < 0) {
            // we insert before the first element
            newRecord->setNext(_headRecord);
            _headRecord = newRecord;
        } else {
            _headRecord->insert(newRecord);
        }
    }
}

  void menuSelection(int selection, GradeBook& gradeBook) {

    string firstName;
    string lastName;
    string courseName;
    char letterGrade;

    switch(selection) {
        case 1: cin >> lastName.c_str() >> firstName.c_str() >> courseName.c_str() >> letterGrade;
                gradeBook.addRecord(lastName, firstName, courseName, letterGrade);
        case 4: gradeBook.read("students.txt");
                gradeBook.displayAllRecords();
                break; 
        case 5: gradeBook.write("students1.txt");
                break; 
        default: cout << "Enter a valid choice.\n"; 
        } 

        if (selection != 5) {
            displayMenu();
            cin >> selection; 
            menuSelection(selection, gradeBook);
        }
} 

void header() {
    cout << "STUDENT GRADEBOOK AND GPA CALCULATOR\n";
    cout << "=====================================\n";
}

void main()
{
    GradeBook gradeBook;

    int userSelection;
    header();
    displayMenu();
    cin >> userSelection; // get the user input for menu selection
    menuSelection(userSelection, gradeBook);
    
    char pause;

    std::cin >> pause;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:38:57+00:00Added an answer on May 24, 2026 at 12:38 pm
    cin >> lastName.c_str() >> firstName.c_str() >> courseName.c_str()
        >> letterGrade;
    

    I don’t think you really want to do that. c_str() is to turn a regular C++ std::string into an old C-style “string” for use with functions that expect such a beast.

    If you’re trying to input a regular C++ string, you should change that to:

    cin >> lastName >> firstName >> courseName >> letterGrade;
    

    In fact, unless you’re using the C library part of C++ (or third-party functions which explicitly requires C “strings”), you should never need to use a char * style of string. Embrace the language and use std::string as much as possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using YUICompressor I get the following error from my javascript code: [ERROR] 270:201:missing name
I have the following code: #include <iostream> #include <string> #include <unistd.h> using namespace std;
Please see the following code: #include <iostream> #include <string> using namespace std; enum dataType
I sometime get following error message: Cannot convert the value in attribute 'Color' to
I get the following compilation error with the following source code: Compilation Error: Type
When merging two code branches in Team Foundation Server I get the following error:
I get the following compilation error: error: expected `;' before 'it' Here's my code:
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
For the following header I get the same two errors on all my sitemaps.
Hi upon compiling this code in Visual studio 2008 i get the following error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.