Linked Questions
96 questions linked to/from How to convert a std::string to const char* or char*
7 votes
3 answers
821 views
what is the difference between a[0] and &a[0] in string
string a = "asdf"; cout<<&a[0]; cout<<a[0]; Why are these two outputs different? Why is &a[0] not the address but the whole string?
2 votes
3 answers
10k views
C++ std::stringstream to const char* conversion [closed]
I am trying to convert a stringstream into a const char*, but I always get a blank string. My Code: #include<string> #include<sstream> #include<stdio.h> const char* test(std::...
3 votes
5 answers
6k views
Cannot convert string to const char
I have this function and the compiler yells at me saying "Cannot convert string to const char". void DramaticLetters(string s, short TimeLength) { for(int i = 0, sLen = strlen(s); i < sLen; i+...
2 votes
3 answers
4k views
Converting std string to const char*
I am getting an error when I run this piece of code string line; getline (myfile,line); char file_input[15]; strncpy(file_input, line, 6); cout << line << endl; Error - cannot ...
-8 votes
1 answer
3k views
How do I rename a file with a string using the rename() function (c++)? [closed]
Here is my code: rename("tmp.png", Filename); The 2nd argument in the rename function is a string.(The user decides what the name is) How do I properly code this so that tmp.png is renamed to ...
0 votes
2 answers
5k views
C++ Expression Must Have Class Type - String to const char*
Trying to convert string to const char* gives "expression must have class type" at the bottom line. Tried some variations on converting with no luck. any ideas? string GetMachineID() { ...
1 vote
2 answers
3k views
c++ no suitable conversion function from "std::string" to "const char*" exists
the question as the title suggests, is an error when i was executing my program in the certain part of the password function. actually it is a basic password function which was working properly in ...
0 votes
6 answers
3k views
How to create a char array from string constant?
I try to create a char* values[] for my unittests that will be written but initialized from constants. The naive way throws a warning that ISO C++ forbids it: char* single[1]; single[0] = "foobar"; I ...
2 votes
3 answers
5k views
how convert string to xmlChar
I'm trying to convert a string to an xmlChar. The compiler says no suitable conversion function from const string to xmlChar exists. This is what the code looks like: bool ClassName::openFile(const ...
1 vote
3 answers
1k views
Converting string to const* char
I have two string declarations: killerName victimName I need to convert these two string values to const* char. Example of how I use my method: if (killer.IsRealPlayer) { killerName = killer....
3 votes
2 answers
2k views
conversion between char* and std::string and const char*
I am now using C++ to program a robot using PROS. Pros has a print function, which is taking in a const char*. Now, I'm using lvgl to create my own screen, and I want to replicate the print function. ...
1 vote
1 answer
7k views
How to convert string to const char[] in c++
I am working on a C++ project for a Vex Robot, I am using a function that takes a const char[] but for showing an integer, there is no such function that converts to const char[], so is there a way to ...
0 votes
3 answers
1k views
Getting char * or const char * data from a string breaks for 16 character strings or longer
I have a function string_to_char() which attempts to give me a form of a string which I can pass into a library I am using, which wants char * (but I think works with const char *, so I've been trying ...
1 vote
2 answers
1k views
Unable to return the contents of a vector<char> as a char* pointer
I am trying to store a char* into a struct's char* field. I have tried different things but none of them worked. The problematic piece of code is shown below: pInfo is the object of the struct ...
0 votes
2 answers
2k views
Why does hash<const char*> work for strings but not string variables?
My question is why does the following code work hash<const char*> PassHash; cout << PassHash("Hello World"); But this code wont compile. hash<const char*> PassHash; string ...