I'm getting a compile time error when appending a string to a const char* in C++?
so I'm trying to convert an integer value into a string and then append the string to an already existing const char*. But as mentioned, I'm getting this error:
error: expression must have integral or unscoped enum type.
objDim += objDimStr.c_str();
Any ideas why?
My code is as follows:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = std::to_string(objDimension);
objDim += objDimStr.c_str();
c++ string char
add a comment |
so I'm trying to convert an integer value into a string and then append the string to an already existing const char*. But as mentioned, I'm getting this error:
error: expression must have integral or unscoped enum type.
objDim += objDimStr.c_str();
Any ideas why?
My code is as follows:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = std::to_string(objDimension);
objDim += objDimStr.c_str();
c++ string char
2
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34
add a comment |
so I'm trying to convert an integer value into a string and then append the string to an already existing const char*. But as mentioned, I'm getting this error:
error: expression must have integral or unscoped enum type.
objDim += objDimStr.c_str();
Any ideas why?
My code is as follows:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = std::to_string(objDimension);
objDim += objDimStr.c_str();
c++ string char
so I'm trying to convert an integer value into a string and then append the string to an already existing const char*. But as mentioned, I'm getting this error:
error: expression must have integral or unscoped enum type.
objDim += objDimStr.c_str();
Any ideas why?
My code is as follows:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = std::to_string(objDimension);
objDim += objDimStr.c_str();
c++ string char
c++ string char
edited Nov 20 at 13:48
asked Nov 20 at 12:27
Xyber 101
33
33
2
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34
add a comment |
2
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34
2
2
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34
add a comment |
5 Answers
5
active
oldest
votes
objDim
is a pointer. When you add to the pointer, you will add to the pointer itself and not append anything to the data it points to.
And you can not add everything to a pointer, basically only integer values. And adding two pointers like you do makes no sense at all (which is why it's not allowed).
If you want to be able to append strings, then use std::string
for all strings.
Besides, that you need to use the const
qualifier should also give some hints about that what the pointer is pointing to is constant and therefore can't be modified (including added to).
And in this case you don't need any of the temporary variable objDimension
or objDimStr
(unless you use them later in the code):
std::string objDim = "The object dimension is: " + std::to_string(geo->Dimension());
Here the addition works because there is an overloaded operator+
function that takes the correct arguments in the correct order, and returns a new std::string
object.
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about thec_str()
member function...
– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
add a comment |
I assume you were expecting to get a concatenation of strings. No, it's not how it works. objDim
is but a pointer to a non-modifiable memory area that contains characters. The only possible application of operator +=
to it that would compile is if you were incrementing it by a few characters:
objDim += 11;
std::cout << objDim << 'n'; // prints "dimension is: ";
To concatenate strings you can:
Either assign the result to a
string
object:
std::string result = objDim + objDimStr;
(Note the absence of
c_str
anywhere: you cannot sum two pointers, but there's an overload that can prepend achar
pointer to astd::string
.)
Or give proper type to
objDim
;
std::string objDim{"The object dimension is: "};
objDim += objDimStr;
add a comment |
objDim
is not an std::string
but a pointer, so your concatenation operator (+
) which is defined for std::string
will not work on it.
Define it as an std::string
and you will be able to use it to concatenate other std::string
s to it.
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can doobjDimStr += objDim + objDimStr;
. ThenobjDimStr
will contain what you need in the right order.
– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)
– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
add a comment |
objDim += objDimStr.c_str();
Here you add one pointer to other instead of concatenating the string. You need use std::string to concatenate, for example:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = objDim;
objDimStr += std::to_string(objDimension);
std::cout << objDimStr << std::endl;
add a comment |
You're declaring objDim as a const, which means it can NOT be changed in runtime.
You should either use std::string
instead of const char*
or use strncat
, as seen here: Append to the end of a Char array in C++
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393000%2fim-getting-a-compile-time-error-when-appending-a-string-to-a-const-char-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
objDim
is a pointer. When you add to the pointer, you will add to the pointer itself and not append anything to the data it points to.
And you can not add everything to a pointer, basically only integer values. And adding two pointers like you do makes no sense at all (which is why it's not allowed).
If you want to be able to append strings, then use std::string
for all strings.
Besides, that you need to use the const
qualifier should also give some hints about that what the pointer is pointing to is constant and therefore can't be modified (including added to).
And in this case you don't need any of the temporary variable objDimension
or objDimStr
(unless you use them later in the code):
std::string objDim = "The object dimension is: " + std::to_string(geo->Dimension());
Here the addition works because there is an overloaded operator+
function that takes the correct arguments in the correct order, and returns a new std::string
object.
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about thec_str()
member function...
– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
add a comment |
objDim
is a pointer. When you add to the pointer, you will add to the pointer itself and not append anything to the data it points to.
And you can not add everything to a pointer, basically only integer values. And adding two pointers like you do makes no sense at all (which is why it's not allowed).
If you want to be able to append strings, then use std::string
for all strings.
Besides, that you need to use the const
qualifier should also give some hints about that what the pointer is pointing to is constant and therefore can't be modified (including added to).
And in this case you don't need any of the temporary variable objDimension
or objDimStr
(unless you use them later in the code):
std::string objDim = "The object dimension is: " + std::to_string(geo->Dimension());
Here the addition works because there is an overloaded operator+
function that takes the correct arguments in the correct order, and returns a new std::string
object.
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about thec_str()
member function...
– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
add a comment |
objDim
is a pointer. When you add to the pointer, you will add to the pointer itself and not append anything to the data it points to.
And you can not add everything to a pointer, basically only integer values. And adding two pointers like you do makes no sense at all (which is why it's not allowed).
If you want to be able to append strings, then use std::string
for all strings.
Besides, that you need to use the const
qualifier should also give some hints about that what the pointer is pointing to is constant and therefore can't be modified (including added to).
And in this case you don't need any of the temporary variable objDimension
or objDimStr
(unless you use them later in the code):
std::string objDim = "The object dimension is: " + std::to_string(geo->Dimension());
Here the addition works because there is an overloaded operator+
function that takes the correct arguments in the correct order, and returns a new std::string
object.
objDim
is a pointer. When you add to the pointer, you will add to the pointer itself and not append anything to the data it points to.
And you can not add everything to a pointer, basically only integer values. And adding two pointers like you do makes no sense at all (which is why it's not allowed).
If you want to be able to append strings, then use std::string
for all strings.
Besides, that you need to use the const
qualifier should also give some hints about that what the pointer is pointing to is constant and therefore can't be modified (including added to).
And in this case you don't need any of the temporary variable objDimension
or objDimStr
(unless you use them later in the code):
std::string objDim = "The object dimension is: " + std::to_string(geo->Dimension());
Here the addition works because there is an overloaded operator+
function that takes the correct arguments in the correct order, and returns a new std::string
object.
edited Nov 20 at 12:42
answered Nov 20 at 12:31
Some programmer dude
293k24247408
293k24247408
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about thec_str()
member function...
– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
add a comment |
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about thec_str()
member function...
– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
Okay, but after doing that I will be left with a string. But, I need a const char* type variable to be able to pass it to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ). So, how do I get a string and then pass it into the function suitably?
– Xyber 101
Nov 20 at 12:56
@Xyber101 Well you already seem to know about the
c_str()
member function...– Some programmer dude
Nov 20 at 13:00
@Xyber101 Well you already seem to know about the
c_str()
member function...– Some programmer dude
Nov 20 at 13:00
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
Uhh yeah, that was so simple. I guess I should go through my code first and stop coming here and posting the error. Thanks !
– Xyber 101
Nov 20 at 13:11
1
1
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
@Xyber101 No worries. Sometimes it's much to easy to forget such small simple details. :)
– Some programmer dude
Nov 20 at 13:14
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
A pointer points to constant chars. The pointer itself can be modified. If concatenation was a standard operation in C++, chances are, one could add more characters past the otherwise constant string.
– bipll
Nov 20 at 14:36
add a comment |
I assume you were expecting to get a concatenation of strings. No, it's not how it works. objDim
is but a pointer to a non-modifiable memory area that contains characters. The only possible application of operator +=
to it that would compile is if you were incrementing it by a few characters:
objDim += 11;
std::cout << objDim << 'n'; // prints "dimension is: ";
To concatenate strings you can:
Either assign the result to a
string
object:
std::string result = objDim + objDimStr;
(Note the absence of
c_str
anywhere: you cannot sum two pointers, but there's an overload that can prepend achar
pointer to astd::string
.)
Or give proper type to
objDim
;
std::string objDim{"The object dimension is: "};
objDim += objDimStr;
add a comment |
I assume you were expecting to get a concatenation of strings. No, it's not how it works. objDim
is but a pointer to a non-modifiable memory area that contains characters. The only possible application of operator +=
to it that would compile is if you were incrementing it by a few characters:
objDim += 11;
std::cout << objDim << 'n'; // prints "dimension is: ";
To concatenate strings you can:
Either assign the result to a
string
object:
std::string result = objDim + objDimStr;
(Note the absence of
c_str
anywhere: you cannot sum two pointers, but there's an overload that can prepend achar
pointer to astd::string
.)
Or give proper type to
objDim
;
std::string objDim{"The object dimension is: "};
objDim += objDimStr;
add a comment |
I assume you were expecting to get a concatenation of strings. No, it's not how it works. objDim
is but a pointer to a non-modifiable memory area that contains characters. The only possible application of operator +=
to it that would compile is if you were incrementing it by a few characters:
objDim += 11;
std::cout << objDim << 'n'; // prints "dimension is: ";
To concatenate strings you can:
Either assign the result to a
string
object:
std::string result = objDim + objDimStr;
(Note the absence of
c_str
anywhere: you cannot sum two pointers, but there's an overload that can prepend achar
pointer to astd::string
.)
Or give proper type to
objDim
;
std::string objDim{"The object dimension is: "};
objDim += objDimStr;
I assume you were expecting to get a concatenation of strings. No, it's not how it works. objDim
is but a pointer to a non-modifiable memory area that contains characters. The only possible application of operator +=
to it that would compile is if you were incrementing it by a few characters:
objDim += 11;
std::cout << objDim << 'n'; // prints "dimension is: ";
To concatenate strings you can:
Either assign the result to a
string
object:
std::string result = objDim + objDimStr;
(Note the absence of
c_str
anywhere: you cannot sum two pointers, but there's an overload that can prepend achar
pointer to astd::string
.)
Or give proper type to
objDim
;
std::string objDim{"The object dimension is: "};
objDim += objDimStr;
answered Nov 20 at 12:35
bipll
7,9321825
7,9321825
add a comment |
add a comment |
objDim
is not an std::string
but a pointer, so your concatenation operator (+
) which is defined for std::string
will not work on it.
Define it as an std::string
and you will be able to use it to concatenate other std::string
s to it.
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can doobjDimStr += objDim + objDimStr;
. ThenobjDimStr
will contain what you need in the right order.
– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)
– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
add a comment |
objDim
is not an std::string
but a pointer, so your concatenation operator (+
) which is defined for std::string
will not work on it.
Define it as an std::string
and you will be able to use it to concatenate other std::string
s to it.
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can doobjDimStr += objDim + objDimStr;
. ThenobjDimStr
will contain what you need in the right order.
– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)
– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
add a comment |
objDim
is not an std::string
but a pointer, so your concatenation operator (+
) which is defined for std::string
will not work on it.
Define it as an std::string
and you will be able to use it to concatenate other std::string
s to it.
objDim
is not an std::string
but a pointer, so your concatenation operator (+
) which is defined for std::string
will not work on it.
Define it as an std::string
and you will be able to use it to concatenate other std::string
s to it.
answered Nov 20 at 12:33
P.W
10.9k3742
10.9k3742
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can doobjDimStr += objDim + objDimStr;
. ThenobjDimStr
will contain what you need in the right order.
– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)
– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
add a comment |
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can doobjDimStr += objDim + objDimStr;
. ThenobjDimStr
will contain what you need in the right order.
– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)
– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
Okay, I perfectly get what you are saying, a string will be appended with a string only, not a pointer. But, I need a char* variable, as that is what I have to pass to an API function to display the string on the screen. The function signature is : int RhinoMessageBox ( const char * message, const char * title, UINT type ) ?
– Xyber 101
Nov 20 at 12:52
@Xyber101: Then you can do
objDimStr += objDim + objDimStr;
. Then objDimStr
will contain what you need in the right order.– P.W
Nov 20 at 12:57
@Xyber101: Then you can do
objDimStr += objDim + objDimStr;
. Then objDimStr
will contain what you need in the right order.– P.W
Nov 20 at 12:57
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
Again, that would give me a string wouldn't it? What I need is a char* with the data of the string. How do I do it? Sorry, I am a newbie in C++ and this pointer thing has got me pretty tied up :(
– Xyber 101
Nov 20 at 13:01
@Xyber101:
objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)– P.W
Nov 20 at 13:03
@Xyber101:
objDimStr.c_str()
will give you what you want. It is the C string equivalent (const char*
)– P.W
Nov 20 at 13:03
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
Yeah, thanks :) Thank you so much for your time, P.W !
– Xyber 101
Nov 20 at 13:12
add a comment |
objDim += objDimStr.c_str();
Here you add one pointer to other instead of concatenating the string. You need use std::string to concatenate, for example:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = objDim;
objDimStr += std::to_string(objDimension);
std::cout << objDimStr << std::endl;
add a comment |
objDim += objDimStr.c_str();
Here you add one pointer to other instead of concatenating the string. You need use std::string to concatenate, for example:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = objDim;
objDimStr += std::to_string(objDimension);
std::cout << objDimStr << std::endl;
add a comment |
objDim += objDimStr.c_str();
Here you add one pointer to other instead of concatenating the string. You need use std::string to concatenate, for example:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = objDim;
objDimStr += std::to_string(objDimension);
std::cout << objDimStr << std::endl;
objDim += objDimStr.c_str();
Here you add one pointer to other instead of concatenating the string. You need use std::string to concatenate, for example:
const char* objDim = "The object dimension is: ";
int objDimension = geo->Dimension();
std::string objDimStr = objDim;
objDimStr += std::to_string(objDimension);
std::cout << objDimStr << std::endl;
answered Nov 20 at 12:45
serge
59537
59537
add a comment |
add a comment |
You're declaring objDim as a const, which means it can NOT be changed in runtime.
You should either use std::string
instead of const char*
or use strncat
, as seen here: Append to the end of a Char array in C++
add a comment |
You're declaring objDim as a const, which means it can NOT be changed in runtime.
You should either use std::string
instead of const char*
or use strncat
, as seen here: Append to the end of a Char array in C++
add a comment |
You're declaring objDim as a const, which means it can NOT be changed in runtime.
You should either use std::string
instead of const char*
or use strncat
, as seen here: Append to the end of a Char array in C++
You're declaring objDim as a const, which means it can NOT be changed in runtime.
You should either use std::string
instead of const char*
or use strncat
, as seen here: Append to the end of a Char array in C++
answered Nov 20 at 12:34
Rafael de Freitas
145
145
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393000%2fim-getting-a-compile-time-error-when-appending-a-string-to-a-const-char-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
They're addresses, so that's like adding 1428, Elm Street to 946, Elderberry Road and expecting Elderberry Road to attach to Elm Street.
– molbdnilo
Nov 20 at 12:34