Hello everyone, So I'm learning how to use arrays and I was given the task to write a program that declares 10 arrays and asks the user to input a name for each variable in the array... afterwards I was asked to do apply a bubble sort to put the names in order... I have never used a bubble sort before, the code for the bubble sort was given to us.. and I tried to apply it to my program... and I did, but I get an error message when I'm using strcmp(string1[i],string1[j]) Which tells me the following: "No suitable conversion function from "std::string" to "const char" exists"
#include "stdafx.h"
#include <string>
#include <iostream>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string names[10] = { " " };
for (int index = 0; index <= 9; index++)
{
cout << "Enter name " << index + 1 << ": ";
cin >> names[index];
}
cout << endl;
string tmp;
for (int i = 1; i < 10; ++i) {
{
for (int j = 4; j >= i; --j)
{
if (strcmp(names[j - 1], names[j]) > 0)
{
tmp = names[j - 1];
names[j - 1] = names[j];
names[j] = tmp;
}
}
}
system("Pause");
return 0;
}
I'll pull this part out of the codr, it's the bubble sort that they provided us and this is where I'm stuck...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
string tmp;
for (int i = 1; i < 10; ++i) {
{
for (int j = 4; j >= i; --j)
{
if (strcmp(names[j - 1], names[j]) > 0) /* This is where I get the error message...
"No suitable conversion function from "std::string" to "const char" exists"
red lines under the arrays of names... */
{
tmp = names[j - 1];
names[j - 1] = names[j];
names[j] = tmp;
}
}
}