【发布时间】:2013-04-19 15:29:13
【问题描述】:
这是我的代码,
#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 string。
顺便说一句,我还必须按字母顺序排列这些,我目前的工作是否有效?我的教授说计算机应该评估字符串的 char 值。
【问题讨论】:
-
我们实际上并没有对向量做太多事情,对于这个特殊的分配,它被分配为一个字符串数组
标签: c++ string function visual-c++ intellisense