所以这是我的代码,
#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;
}
}
由四个星号括起来的行是我尝试构建时错误代码引用的行。我的实际代码中没有星号。我不明白如何修复错误
Intellisense: no suitable conversion function from "std::string" to "std::string *" exists
我已经浏览了一页又一页的搜索,但是所有问题/答案似乎都指的是来自string to int
or string to char
etc. not的转换函数string to string
。
在旁注中,我还必须按字母顺序排列这些,我目前有什么工作吗?我的教授说计算机应该评估字符串的 char 值。