0

所以这是我的代码,

#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 intor string to charetc. not的转换函数string to string

在旁注中,我还必须按字母顺序排列这些,我目前有什么工作吗?我的教授说计算机应该评估字符串的 char 值。

4

2 回答 2

2

这是错误的:

displayNames(names[NUM_NAMES], NUM_NAMES);

这是正确的:

displayNames(names, NUM_NAMES);
于 2013-04-19T15:33:23.773 回答
0

您应该将名称发送到函数而不是名称 [NUM_NAMES]。names 是数组或字符串指针,但 names[NUM_NAMES] 是字符串。您的函数需要一个字符串指针。

std::String[] 等同于 std::String*

于 2013-04-19T15:33:23.987 回答