C++ 我怎样才能摆脱这个“问题”;Intellisense:没有来自“的合适转换函数”;std::string";至;标准::字符串*”;“存在”;错误?
这是我的密码C++ 我怎样才能摆脱这个“问题”;Intellisense:没有来自“的合适转换函数”;std::string";至;标准::字符串*”;“存在”;错误?,c++,string,function,visual-c++,intellisense,C++,String,Function,Visual C++,Intellisense,这是我的密码 #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, T
#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;
}
}
我已经浏览了一页又一页的搜索,但是所有的问题/答案似乎都是指从字符串到int
或字符串到char
等的转换函数,而不是字符串到字符串的转换函数
顺便说一句,我也必须按字母顺序排列这些,我目前拥有的东西有用吗?我的教授说计算机应该评估字符串的字符值。这是错误的:
displayNames(names[NUM_NAMES], NUM_NAMES);
这是正确的:
displayNames(names, NUM_NAMES);
您应该向函数发送名称,而不是名称[NUM_names]。名称是数组或字符串指针,但名称[NUM_names]是字符串。函数采用字符串指针
std::String[]与std::String*完全相同,实际上我们对向量没有做太多的处理,对于这个特殊的赋值,它被赋值为一个字符串数组
displayNames(names, NUM_NAMES);