Reputation: 323
So here's my code,
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int NUM_NAMES = 20;
string names [NUM_NAMES] = {"Collins, Bill", "Smith, Bart" , "Allen, Jim", "Griffin, Jim", "Stamey, Marty", "Rose, Geri","Taylor, Terri",
"Johnson, Jill", "Allison, Jeff", "Looney, Joe" , "Wolfe, Bill", "Rutherford, Greg", "Javens, Renee","Harrison, Rose","Setzer, Cathy",
"Pike, Gordon","Holland, Beth"};
string smallest;
int minindex;
void displayNames (string[NUM_NAMES], int);
cout<<"Here are the unalphabetized names";
****displayNames(names[NUM_NAMES], NUM_NAMES);****
for(int i=0; i < (NUM_NAMES -1); i++)
{
minindex=i;
smallest=names[i];
for(int j = (i+1); j<NUM_NAMES; j++)
{
if(names[j]<smallest)
{
smallest = names[j];
minindex = j;
}
}
names[minindex] =names[i];
names[i] = smallest;
system("pause");
return 0;
}
}
void displayNames(string names[], int NUM_NAMES)
{
for (int i =0; i<NUM_NAMES; i ++)
{
cout<<names[i]<<endl;
}
}
The line bracketed by four asterisks is the line that the error code references when I try to build. The asterisks are NOT there in my actual code. I don't understand how to fix the error
Intellisense: no suitable conversion function from "std::string" to "std::string *" exists
I've gone through pages and pages of searches, however all the questions/answers appear to refer to a conversion function from string to int
or string to char
etc. not string to string
.
On a side note, I do also have to alphabetize these, will what I currently have work? My professor was saying that the computer should evaluate the strings' char values.
Upvotes: 0
Views: 5166
Reputation: 359
You should send names to the function not names[NUM_NAMES]. names is an array or a string pointer but names[NUM_NAMES] is a string. Your function takes a string pointer.
std::String[] is identical to std::String*
Upvotes: 0
Reputation: 9609
This is wrong:
displayNames(names[NUM_NAMES], NUM_NAMES);
This is the correct one:
displayNames(names, NUM_NAMES);
Upvotes: 2