String convertion in c/c++?
-
Hello? Is there any way to convert:
char* to const char*
const char* to char*string to const string
const string to stringthanks in advance
It is never late to learn
-
Hello? Is there any way to convert:
char* to const char*
const char* to char*string to const string
const string to stringthanks in advance
It is never late to learn
-
Hello? Is there any way to convert:
char* to const char*
const char* to char*string to const string
const string to stringthanks in advance
It is never late to learn
Yes.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Hello? Is there any way to convert:
char* to const char*
const char* to char*string to const string
const string to stringthanks in advance
It is never late to learn
-
Hello? Is there any way to convert:
char* to const char*
const char* to char*string to const string
const string to stringthanks in advance
It is never late to learn
I think what you're looking for is
const_cast
e.g.char* pszData = "Letters and stuff."; const char* pszFixedText = const_cast< const char* >( pszData ); char* pszModifiable = const_cast< char* >( pszFixedText );
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
-
Yes.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
People really don't like good answers. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
People really don't like good answers. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I was feeling generous. You know, I'm all for helping folks out of a jam, and even going the extra mile on occasion, but there comes a point when these posters have to grow up and start getting a clue. This next generation of developers is scaring me!
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
I was feeling generous. You know, I'm all for helping folks out of a jam, and even going the extra mile on occasion, but there comes a point when these posters have to grow up and start getting a clue. This next generation of developers is scaring me!
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
Well, univoters are even worse: IMHO your answer is brilliant because (1) it is actually true. (2) enlights the inconsistency of the question. Univoting people cannot appreciate the above. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I think what you're looking for is
const_cast
e.g.char* pszData = "Letters and stuff."; const char* pszFixedText = const_cast< const char* >( pszData ); char* pszModifiable = const_cast< char* >( pszFixedText );
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
You don't need a cast to go from
T*
toconst T*
. And please don't suggest a cast for going fromconst T*
toT*
without knowing what the OP is actually doing. Teaching new C++ programmers that casts solve everything is really detrimental.--Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen
-
You don't need a cast to go from
T*
toconst T*
. And please don't suggest a cast for going fromconst T*
toT*
without knowing what the OP is actually doing. Teaching new C++ programmers that casts solve everything is really detrimental.--Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen
Indeed, I didn't say this was good or recommended only that it was what he was looking for. In fact I'm no fan of the way const-ness is implemented in C++ at all and I don't take it nearly to the 'religious' extremes that some people do. I'd also prefer it if all type casts had to be explicitly implemented, even for builtin types but that's another issue. :)
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)