Questions tagged [const-char]

68 questions
3
votes
2 answers

Proper memory cleanup with c_str() and const char *

I have a function that takes a (char* const*). The data I am provided is in a std::string. So I'm doing this: void blahblah(std::string str) { const char * cc = str.c_str(); ConstCharFunction(&cc); } This works well. My question is do I need…
user3758015
  • 119
  • 1
  • 9
3
votes
1 answer

How to pass string between c++ and c# with null characters inside?

In C++ I have some strings, for example string str = "a\0b\0c"; And I need to pass this string to C# without losing data after "\0",and from c# pass to C++ also without losing data. Can you help me?
Pavlo Denys
  • 81
  • 1
  • 6
3
votes
7 answers

How do I properly turn a const char* returned from a function into a const char** in C?

In short, I would like to do this: const char **stringPtr = &getString(); However, I understand that you can't & on rvalues. So I'm stuck with this: const char *string = getString(); const char **stringPtr = &string; I can live with two lines. Am…
spirulence
  • 701
  • 3
  • 11
3
votes
3 answers

How to convert const char* to const WCHAR*

I have something like this: if(GetFileAttributesW("C:\\Directory")!="INVALID_FILE_ATTRIBUTES") {...} I get error: cannot convert 'const char*' to 'const WCHAR*' for argument '1' to 'DWORD GetFileAttributesW(const WCHAR*)' How to convert const char*…
burtek
  • 2,576
  • 7
  • 29
  • 37
2
votes
1 answer

Qt 5 Logging - defining category with QLoggingCategory

I have a problem with QLoggingCategory(const char * category). When I use it like: QString rt = "3"; QString sv = "P"; QLoggingCategory dailyLogger(QString(rt+sv+"Logger").toStdString().c_str()); it doesn't work (my custom message handler doesn't…
lazare
  • 31
  • 3
2
votes
2 answers

casting away the constness using const_cast

No. This question in NOT duplicate of When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? The question asked here is no ways similar to the link described as duplicate. First question : I am using const_cast below for…
anurag86
  • 1,635
  • 1
  • 16
  • 31
2
votes
1 answer

const char pointer declaration in struct

I'm trying to do this, but my compiler won't let me: struct { const char* string = "some text"; } myAnonymousStruct; I believe it's because no assignments can be made in a struct declaration - they're supposed to be made in…
Codesmith
  • 5,779
  • 5
  • 38
  • 50
1
vote
3 answers

How come XDrawString doesn't take "const char *"?

looking at the declaration for XDrawString from X11, it is int XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, int length); How come the 6th argument is type "char *" instead of "const char *"? Does…
user102008
  • 30,736
  • 10
  • 83
  • 104
1
vote
1 answer

How do I convert a String into a char in C++

I want to convert a string that is inside a vector of strings (vector) into a char. The vector would look something like the following: lons = ["41", "23", "N", "2", "11" ,"E"]. I would like to extract the "N" and the "E" to convert them into a…
Nhenon
  • 49
  • 7
1
vote
3 answers

How can I join a char to a constant char*?

I have a function that joins two constant char* and returns the result. What I want to do though is join a char to a constant char* eg char *command = "nest"; char *halloween = join("hallowee", command[0]); //this gives an error char *join(const…
pnizzle
  • 6,243
  • 4
  • 52
  • 81
1
vote
1 answer

String and Variable combination

i m a beginner in c++ and i have a question. how can i combine a variable and a string in the folowing line. QMessageBox::Question(this,"Report", "the Report is in Path: " + pdfPath + "saved, do you want to open it", QMessageBox::Yes |…
Boumo
  • 19
  • 2
1
vote
0 answers

converting const char to string isn't working

Trying to convert type const char to type std::string. All the examples I've seen are for const char *. If I change my type to * the dc.at will fail. The conversion to string is failing. I've been trawling for an hour, it can't be that hard, I'm…
Dan
  • 2,304
  • 6
  • 42
  • 69
1
vote
2 answers

Trying to connect to ROS using rosserial-windows . Error with the IP address

I am trying to connect to ROS using rosserial windows. I am following the tutorial given on the ROS website (http://wiki.ros.org/rosserial_windows/Tutorials/Hello%20World) here is what my code looks like: // ConsoleApplication1.cpp : Defines the…
sdcguy
  • 11
  • 1
1
vote
2 answers

Different results for QString to const char*

I have a code snippet to test a code bug. #include #include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString name = QString("Lucy"); QString interest =…
user3857893
  • 63
  • 1
  • 5
1
vote
1 answer

C++ MFC missing const char* variable

So I have that simple code inside button click method: std::stringstream ss; unsigned counter = 0; while(true) { ss.clear(); ss << DEFAULT_USER_CONFIG_NAME << " " << ++counter; const char* name = ss.str().c_str(); MessageBox(name); …
Arrekin
  • 95
  • 5