By N. Yeshikhin

2018-07-11 23:32:13 8 Comments

As I know in C++ you can change the value of (char *) variable , but I have an error.

This is a screenshot.

The error is:

error C2440: '=': cannot convert from 'const char [71]' to 'char *'

before I declared a char* variable:

char *sql;

and then I want to use it, but:

sql = "INSERT INTO person (id,name,last,age) "  \
    "VALUES (1, 'Paul', 'Yezh', 14); ";

On the equal sign I have this error.


@1201ProgramAlarm 2018-07-11 23:44:51

Since character strings are constant arrays, you need to change the type of sql to const char *sql.

@Fei Xiang 2018-07-11 23:45:30

Or copy the string if it needs to be modified.

@Brian 2018-07-11 23:57:50

This answer is correct. Consider also that all compiler errors are well documented online. See here for a clear and easy explanation of the C2440 error. Always check documentation.

Related Questions

Sponsored Content

34 Answered Questions

10 Answered Questions

16 Answered Questions

[SOLVED] Default value to a parameter while passing by reference in C++

23 Answered Questions

[SOLVED] Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

10 Answered Questions

3 Answered Questions

[SOLVED] C++ getting error C2440

  • 2014-08-07 15:35:20
  • user3735032
  • 11353 View
  • 3 Score
  • 3 Answer
  • Tags:   c++ c visual-c++

1 Answered Questions

C++03: _ui64toa_s: error C2446: ':' : no conversion from 'errno_t' to 'const char *'

  • 2015-02-20 01:11:14
  • user3555181
  • 501 View
  • -1 Score
  • 1 Answer
  • Tags:   c++

31 Answered Questions

[SOLVED] Why is this program erroneously rejected by three C++ compilers?

5 Answered Questions

[SOLVED] Float, Double, Char, C++ Errors. What is wrong?

4 Answered Questions

[SOLVED] How to add strings to a 2d array of char elements?

Sponsored Content