| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cannot convert from 'const char [11]' to 'char [25]'
I am fairly new to C++, I have started to write some code and i have realised that i am having dificulty assigning char values, there is probably a very easy solution i just can't think/remember it.
Code:
#include <iostream>
using namespace std;
//define structure Station
struct Station {
int ID;
int Founded;
char Name[25];
int NextClockwise;
int NextAnti;
Station* NextP;
};
int main()
{
//declare atart and current pointers
typedef Station* StartP;
Station* CurrentP;
CurrentP=new Station;
//dynamically allocation
CurrentP->ID=1;
CurrentP->Founded=1863;
CurrentP->Name="Padington";
CurrentP->NextClockwise=0;
CurrentP->NextAnti=0;
CurrentP->NextP=NULL;
|
|
#2
|
||||
|
||||
|
Check out the strcpy or sprintf functions. Although since you're using c++ you might want to leave these c-style functions and use the string class instead of char pointers/arrays.
|
|
#3
|
||||
|
||||
|
Forget that i said strcpy by the way, always try to use strncpy instead..
|
|
#4
|
|||
|
|||
|
Quote:
thanks, i'm using string class and it works |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Cannot convert from 'const char [11]' to 'char [25]' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|