const-char Questions

7

Solved

In my project there is a method which only returns a const char*, whereas I need a char* string, as the API doesn't accept const char*. Any idea how to convert between const char* to char*?
Hurlee asked 28/8, 2014 at 13:6

10

Solved

The only way I know is: #include <sstream> #include <string.h> using namespace std; int main() { int number=33; stringstream strs; strs << number; string temp_str = strs.str...
Kym asked 1/6, 2012 at 8:53

1

Solved

Normally, I would return a std::string from a function because returning a const char* would require the caller to provide an output memory buffer, and that buffer is not resizable. But is r...
Crispation asked 20/12, 2017 at 5:7

2

Solved

I am extending Python with some C++ code. One of the functions I'm using has the following signature: int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, char *format, char **kwlist...
Dyche asked 8/4, 2010 at 15:32

5

Solved

I'm trying to write a program in C++, which creates some files (.txt) and writes down the result in them. The problem is that an amount of these files is not fixed at the beginning and only appears...
Carltoncarly asked 28/10, 2012 at 12:58

2

Solved

This question relates directly to using char as a key in stdmap. I understand what the compare function passed in does and why its required for char * types as a key. However, I'm uncertain as how...
Condyloid asked 15/10, 2012 at 18:23

2

Solved

i'm new to c++ and have a lack of understanding why this code works well: string GetString(string promt) { cout << promt << ": "; string temp; getline(cin, temp); return temp; } ...
Unattended asked 30/8, 2012 at 0:20

3

Solved

I have seen people using 2 methods to declare and define char *. Medhod 1: The header file has the below extern const char* COUNTRY_NAME_USA = "USA"; Medhod 2: The header file has the below dec...
Dim asked 21/5, 2010 at 4:23

3

Solved

I am stuck in a printf problem. I would appreciate if I can get some help here: In the below code, I can see the font family get displaced correctly in first printf(), but if I set it to variable, ...
Schmitt asked 5/3, 2010 at 21:42

4

Solved

It seems that strtol() and strtod() effectively allow (and force) you to cast away constness in a string: #include <stdlib.h> #include <stdio.h> int main() { const char *foo = "Hello...
Crispen asked 14/6, 2009 at 20:36
1

© 2022 - 2024 — McMap. All rights reserved.