-
C++ (
http://www.daniweb.com/forums/forum8.html)
| hellokitty88 | Mar 16th, 2008 5:39 am | |
| Search string? I am trying to do a sequential string, but when I run my program I recieve three errors:the first one talks about 'searchList' : cannot convert parameter 3 from 'const char [4]' to 'std::string []
( I tried putting code tags by inserting my code between the , but I am not positive if it is displaying) Sorry for any convenience!
#include <iostream>
#include <fstream>
using namespace std;
int searchList(string array[], int, string value[]);
const int ARRAY_SIZE = 3;
int main()
{
string someArray[ARRAY_SIZE] = {"mouse", "cat", "ant"};
int results;
results = searchList(someArray, ARRAY_SIZE, "ant");
if (results == -1)
cout << "You did not earn 100 points on any test\n";
else
{
cout << "You earned 100 points on test ";
cout << (results + 1) << endl;
}
return 0;
}
int searchList(string array[], int numElems, string value[])
{
int index = 0; // Used as a subscript to search array
int position = -1; // To record position of search value
bool found = false; // Flag to indicate if the value was found
cout << "made it here" << endl;
while (index < numElems && !found)
{
if (array[index] == value[]) // If the value is found
{
found = true; // Set the flag
position = index; // Record the value's subscript
}
index++; // Go to the next element
}
return position; // Return the position, or -1
} |
| Ancient Dragon | Mar 16th, 2008 8:26 am | |
| Re: Search string? remove the brackets from the last parameter -- it should not be an array
int searchList(string array[], int numElems, string value); |
| All times are GMT -4. The time now is 1:30 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC