top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Converting char * into the string?

0 votes
235 views

I have a function which takes string as an argument, but while calling this function I am actually passing char * (not const char *). This function uses the argument and populate the private variable which is of string type.

In the product its showing some strange behaviour i.e. crashing once in a while (not always) in other function while accessing the string variable which is class variable. Just want to check if the issue is with the passing of the variable which is of char * type.

void myfunc(char * Id)
{
    abc.fetchInfo(Id);
    ...
    ...
}

Definition of the fetchInfo 
fetchInfo(std::string Id);
posted Apr 12, 2013 by Salil Agrawal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Should work fine.
May be you can add an assert on char* Id not null, and is a valid c-string null terminated (probably yes in all cases)

answer Apr 12, 2013 by anonymous
0 votes

Why not simply use:
abc.fetchInfo(std::string(Id));

answer Apr 12, 2013 by anonymous
Similar Questions
+1 vote

Is there any method in c++ to find the multiple position of a char in a string.
eg : Hi, How are you?
position of H : 1 and 5

+1 vote

Just curious:

Take a switch-statement like -

switch(myVar)
{
    case(label):
    ...
    break;
}

why label should be constant only?

+3 votes

I need help in writing the code where I enter the input in which each char is followed by its occurrence and output should be absolute string.

Example
Input a10b5c4
Output aaaaaaaaaabbbbbcccc

+2 votes

A char can not be a +ve or -ve. last bit is signed bit in accumulator.but not useful for CHAR Whats the purpose? of doing it.

...