【发布时间】:2011-12-16 03:43:24
【问题描述】:
我正在尝试编写一个代码,该代码应该允许我搜索我在提示时输入的数组字符串。程序要求用户输入一定数量或数据,然后要求用户执行搜索。我很难搜索输入。我可以用整数做到这一点,但现在字符串请帮忙。你会怎么做呢。
#include <iostream>
using namespace std;
void contactArray(string a[], int size);
string search(const string a[], int size, string find);
int main( )
{
cout << "This program searches a list .\n";
const int arraySize = 3;
string a[arraySize];
contactArray(a, arraySize);
string find;
cout << "Enter a value to search for: ";
cin >> find;
string lookup = search(a, arraySize, find);
if (lookup == " ")
cout << find << " is not in the array.\n";
else
cout << find << " is element " << lookup << " in the array.\n";
return 0;
}
void contactArray(string a[], int size)
{
cout << "Enter " << size << " list.\n";
for (int index = 0; index < size; index++)
cin >> a[index];
}
int search(const string a[], int size, string find)
{
string index = "";
while ((a[index[3]] != find) && (index < size))
cout<<"try again"<<endl;
if (index == find)
index = "";
return index;
cout<<"hgi";
}
【问题讨论】:
-
这是作业吗?如果是这样,请添加
homework标签
标签: c++ visual-c++