繁体   English   中英

如何摆脱“智能感知:没有合适的转换函数从”std :: string“到”std :: string *“存在”错误?

[英]How do I get rid of the “Intellisense: no suitable conversion function from ”std::string“ to ”std::string *“ exists” error?

所以这是我的代码,

#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 intstring to char等的转换函数, string to int不是string to string

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

这是错的:

displayNames(names[NUM_NAMES], NUM_NAMES);

这是正确的:

displayNames(names, NUM_NAMES);

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

std :: String []与std :: String *相同

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM