-
January 12th, 2021, 01:19 PM
#1
How to return the value of a const char* method
Hey guys, I am just starting to learn C++ here, and I am a bit confused by this method:
Code:
extern const char* getOwnerSerNoString(void);
which is defined as follows:
Code:
const char* getOwnerSerNoString(void)
{
const char* result = FileData[FILE_ID_TJ_INFO].OwnerSerNoStr;
if ( !strcmp( result, "" ) )
{
result = FileData[FILE_ID_LH_INFO].OwnerSerNoStr;
}
return result;
}
it seems to be returning a char[] which I believe in C++ is just a string, correct? So, if I want to get the full string itself, and convert it to an actual string using what would that look like? Do I need a loop for that?
-
January 12th, 2021, 02:18 PM
#2
Re: How to return the value of a const char* method
Code:
std::string myString = getOwnerSerNoString();
Victor Nijegorodov
-
January 13th, 2021, 12:52 PM
#3
Re: How to return the value of a const char* method
Okay, so I think I get it now. When you have a * it's sort of just a way of pointing at the original data rather than re-declaring it. I thought maybe I had to use the & operator somehow but I guess that's if I want to access the location in memory where the data is stored.
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
|