Declaring a String Array

I'm having trouble with this declaration. I've tried every way that I can think of but I keep getting more and more error messages. This is the least I could manage. The program is supposed to accept a name and then check to see if it is on the list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    int i, ctr=0;
    string n;
    int string name["Andre","Auset","Caroline","Chris B.","Chris S.","Corbin","Janay","Jason","Jawwaad","Kathleen","Kristyll","Malik","Quinn","Ravenn","Travis","Tyler"];
    
    cout<<"Please input name: ";
    cin>>n;
    
    for(i=0; i<15; i=i+1)
    {
           if (name[i]==n)
           ctr++;
    }
    
    if (ctr==0)
    cout<<n<<" is not on the list";
    else
    cout<<n<<" is on the list";


These are the errors:

`string' does not name a type - line 9
`name' undeclared (first use this function) - line 16
Last edited on
I've tried every way that I can think of
It seems so. When in doubt, consult the reference
1
2
3
#include <string> // no .h (that's cstring)
//...
string name[] = {"Andre", "Auset" , /*...*/ "Tyler"}; 
Thank you so much! It's running properly now. I guess that's what happens when you never properly understood string syntax.
Topic archived. No new replies allowed.