Questions tagged [const-char]

68 questions
1
vote
1 answer

counting algorithm and pointer types

I wrote the following code as an exercise about function templates and template specializations. It's a function that counts how many objects of a given type are present in a vector: template int function(const std::vector &vec, T…
Luca
  • 1,658
  • 4
  • 20
  • 41
1
vote
1 answer

Initialize const char* by concatenating another char*

I want to refactor: const char* arr = "The " "quick " "brown"; into something like: const char* quick = "quick "; const char* arr = "The " quick "brown"; because the string "quick" is used is many other places. Ideally I need to be…
user3757652
  • 35
  • 1
  • 2
  • 6
1
vote
1 answer

Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value?

While adding a detailed answer, I noticed that GCC does not warn the following code while Visual C++ complains. #include int main() { const char CONSTSTR[] = "foo/bar/foobar.txt"; char *nonconst = std::strrchr (CONSTSTR, '/'); …
oHo
  • 51,447
  • 27
  • 165
  • 200
1
vote
3 answers

Compare Objective-C const char with NSString

I was wondering if there is a simple way to compare a const char with an NSString, or do I have to convert the const char to an NSString before doing do? I have been looking through Apple docs but struggling to find an answer to my question.
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183
1
vote
1 answer

const char * changing value during loop

I have a function that iterates through a const char * and uses the character to add objects to an instance of std::map if it is one of series of recognized characters. #define CHARSEQ const char* void compile(CHARSEQ s) throw…
ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
0
votes
1 answer

const char* convert have problem result in print nothing

I try to convert uint64_t to const char *. But I find If I use const char *sz2 = std::to_string(channel_id2).c_str();, it print nothing. when I use string to take std::to_string(channel_id2)'s result and convert the string to const char *, it can…
cat
  • 11
  • 1
0
votes
0 answers

Error invalid conversion from 'const char*' to 'char*'

I Expect to get the name which I sent to the "class stud" which has a class variable CHAR name The issue appears specifically at this line this->name->set_name_send(OBJ.name->get_name()); and I get this error " -- invalid conversion from 'const…
Ghips
  • 1
  • 1
0
votes
2 answers

custom exception class, using a base class, with multiple arguments

So I'm setting up custom exception classes for a program I am writing. I'm creating a catch-all base class, that I will use primarily as a generic exception. This base class will be inherited by several other custom exceptions. Here is the base…
Michael
  • 174
  • 2
  • 13
0
votes
2 answers

Can not covert from 'const char*' to 'char*' in VS19, although earlier could

I bought a Surface Go 2 today, and installed Visual Studio 2019. I loaded my project, that successfully compiled on my previous PC, also in VS19. The first problem that I noticed is that the VS editor displays Unicode characters (Cyrillic) in my…
0
votes
0 answers

argument of type "WCHAR *" is incompatible with parameter of type "const char *"

I get this message and i dont know what to do. argument of type "WCHAR *" is incompatible with parameter of type "const char *" this is the code(it has a problem with the modEntry) uintptr_t GetModule(const char* modName, DWORD procId) { HANDLE…
0
votes
1 answer

Returning and Printing Strings in C++

I am trying to get a file path from the user in the getPath() function and return the path as a string. I am having trouble because the compiler says i need to use const char's and i dont know how to do that. How would I use const chars and what…
0
votes
2 answers

Is const char* automatically deleted when it is passed as an argument?

When I pass a const char* as a function argument (like this): void print(const char* text) { std::cout << text << std::endl; } Is it automatically deleted? If not, what happens to it, and how should I delete it?
0
votes
2 answers

Lambda: Is capture of const char * from function scope in lambda undefined behaviour

I have a lambda which uses a const char * defined in function scope. The lambda is executed after the function returns. void function() { const char * UNLOCK_RESULT = "unlockResult"; .. .. TestStep::verifyDictionary(test,…
Andrew Goedhart
  • 937
  • 9
  • 17
0
votes
6 answers

Program hanging while running, compiles well

EDITED : #include using namespace std; #include #include void dfsvisit(int a[][30], int i, const char *color[]) { int v; int p[30]; int f[30]={}; static int j=1; …
Ava
  • 5,783
  • 27
  • 58
  • 86
0
votes
2 answers

C++ Get length of const char* [ ] in vector

How do I get the length of const char* arrays indexes? The vector: std::vector _infoBarText; The const char* []: const char* text[4] = {"Current T:", "Target T:", "Time elapsed:", "Time remaining:"}; Assigning the char array to the…
Daan van Driel
  • 165
  • 1
  • 2
  • 9