November 26th, 2012, 09:19 AM
#1
[RESOLVED] How to access the value to which const char* const points?
Hi,
I need to check if the pointer const char* const points to an empty string.
Something like this:
Code:
const char* const a = ...
if (&a == "") {
cout << "empty string!";
}
However, the code above gives me an error:
error C2446 '==': no conversion from 'const char*' to 'const char *const *'
so I guess I am doing something wrong.
Could someone help please?
Thanks.
November 26th, 2012, 09:24 AM
#2
Re: How to access the value to which const char* const points?
I mean I don't actually assign anything to 'a' myself (just realised that the line
Code:
const char* const a = ...
would probably not work and might just confuse everybody).
November 26th, 2012, 09:40 AM
#3
Re: How to access the value to which const char* const points?
& is the address of operator. Your code is attempting to get the address of a pointer. There are several options, assuming the pointer is not null, including...
if(a[0] == 0)
if(strlen(a) == 0)
November 26th, 2012, 09:48 AM
#4
Re: How to access the value to which const char* const points?
GCDEF, thanks for your reply.
I just found another option that seems to work:
if (*a == '\0')
Is this also a correct way?
November 26th, 2012, 09:50 AM
#5
Re: How to access the value to which const char* const points?
Originally Posted by
monday-to-friday
GCDEF, thanks for your reply.
I just found another option that seems to work:
if (*a == '\0')
Is this also a correct way?
That's fine too.
November 26th, 2012, 10:29 AM
#6
Re: How to access the value to which const char* const points?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks