Super noob trying to learn basic char vektors

Hi, i just started trying to learn c++ a week ago, so i hope you excuse my basic question, and i hope you keep your answers basic as well :)

Anyways, i have tried making basic vektors with numbers, which have not been a problem, but now im trying to make a string with characters, and my compiler just doesnt understand me. I hope someone has an answer for me

EDIT: My errors are on line 7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
	bool ok=false;
	char teck[18]={A,T,V,R,E,L,I,C,K,a,t,v,r,e,l,i,c,k};
	char let;
	cout<<"Enter a character, or the number '0' to exit: ";
	cin>>let;
		if (let==0)
		{
			cout<<"You're done'";
			getch();
			return 0;
		}
	for (int i=0;i<18;i++)
		if (teck[i]==let)
		{
			ok=true;
			break;		
		}
	if (ok)
	cout<<"Your character is in the list!"<<endl;
	else
	cout<<"Youre character is not in the list"<<endl;
	getch();
	return 0;
}
Last edited on
closed account (48T7M4Gy)
chars have to be enclose in quotes eg 'A'
@Line 7. You have an array of characters and characters should be placed within single quotes ''. For Example: char first = 'a';

Similarly for an array of characters, you have to do the same and remember to place '\0' (End) as the last element.

So line 7 will be:

char teck[19] = {'A', 'T', 'V', 'R', 'E' ,'L', 'I', 'C', 'K', 'a', 't', 'v', 'r', 'e', 'l', 'i', 'c', 'k', '\0'};
Last edited on
Thank you, most helpful :)
Topic archived. No new replies allowed.