Why does my program give “NULL used in arithmetic”

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.


Want to improve this question? Update the question so it’s on-topic for Stack Overflow.

Closed 7 years ago.

I wrote the following;

string words;
int a=0;
getline(cin,words);

while(words[a]!=NULL)
{                           
     a++;                    
}        
cout<<a<<endl;

It worked correctly, but when I added the line at the end:

string words;
int a=0;
getline(cin,words);

while(words[a]!=NULL)
{
      a++;                       
}
cout<<a<<endl;

if(words[1]=="a") {cout<<"the letter is a";}

It no longer works. Why?

Leave a Comment