I'm writing a class planner with a structured array declared in the header

#include <string>
using std::string;

struct Classes
{
	string ClassName;
	string ClassNumber;
	string DaysMet;
	int StartTime;
	int	EndTime;
	string Teacher;
	int Students;

};

this is the print function of the program

int Print()
{ 
	system("cls");
	int same=0;
	string query;
	cout << "Enter a class number or \"all\" to retrieve records: ";
	cin >> query;

	if (query == "all")
	{
		
		for(int x=0; x<currentindex; x++)
		{
			cout << "Class Name: " << Course[x].ClassName << endl;
			cout << "Class Number: " << Course[x].ClassNumber << endl;
			cout << "Class meets on: " << Course[x].DaysMet << endl;
			cout << "Starts at: " << Course[x].StartTime << endl;
			cout << "Ends at: " << Course[x].EndTime << endl;
			cout << "Teacher: " << Course[x].Teacher << endl;
			cout << "Students: " << Course[x].Students << endl;
			cout << "" << endl;
		}
		system("PAUSE");
	}
	else 
	{
			for(int x=0; x<=currentindex; x++)
			{
				if (strcmp(Course[x].ClassNumber, query) == 0)	
				{
					cout << "Class Name: " << Course[x].ClassName << endl;
					cout << "Class Number: " << Course[x].ClassNumber << endl;
					cout << "Class meets on: " << Course[x].DaysMet << endl;
					cout << "Starts at: " << Course[x].StartTime << endl;
					cout << "Ends at: " << Course[x].EndTime << endl;
					cout << "Teacher: " << Course[x].Teacher << endl;
					cout << "Students: " << Course[x].Students << endl;
					cout << "" << endl;
					system("PAUSE");
					Menu();
				}
			//	else 
			//	{
			//		cout << "No records exist with that name" << endl;
			//		Menu();
			//	}
			}
	}
return 0;
}

The problem I have is that no matter what type of variable I declare ClassNumber or query as, strcmp gives me the following error:

error C2664: 'strcmp' : cannot convert parameter 1 from 'std::string' to 'const char

Recommended Answers

All 3 Replies

Because strcmp() is C.

You're already half-way there with line 9, so just carry on using == to compare two std::string variables.

You've got to love it when the answer is that simple. Thanks a ton!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.