[英]IntelliSense: no suitable conversion function from “std::string” to “char” exists so how do i go about this?
[英]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 int
或string 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.