如何摆脱“Intellisense:没有合适的转换函数从”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;
}
}
四个星号括起来的行是错误代码引用时,我尝试构建。星号在我的实际代码中不存在。我不明白如何修复错误
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
我已经浏览了页面和页面的搜索, /答案似乎指从 string到int
或 string到char
等的转换函数not string to string
。
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
.
在旁注中,我还必须按字母顺序排列这些,我的教授说计算机应该评估字符串的char值。
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.
推荐答案
这是错误的:
displayNames(names[NUM_NAMES], NUM_NAMES);
这是正确的:
displayNames(names, NUM_NAMES);
这篇关于如何摆脱“Intellisense:没有合适的转换函数从”std :: string“到“std :: string *”存在“错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!