cannot initialize string of structured data

#include <iostream>
#include <conio>
#include <string>

int main()
{

struct LectureInfo
{
string name;
};

LectureInfo dayang = {"Testing"};



getch();
return 0;
}

When i execute the program it mentioned about cannot convert char* to LectureInfo.Actually, it is something wrong with the compiler because i'm running this code in Borland c++ .My friends runs it properly in the Dev C++ compiler without any error.Anyone familiar with Borland C++ and know how to initialize the string value ?
Why don't you use a constructor?

1
2
3
4
5
6
7
struct LectureInfo
{
     string name;
     LectureInfo( string Name ):name(Name) {}
};

LectureInfo dayang = "Testing";
The problem still happened "cannot convert char to LectureInfo"
 
LectureInfo dayang( "Testing" );

If that fails -- it does appear to be a compiler problem. But you should be able to get around it with:

LectureInfo dayang( string("Testing") );
The original poster posted this which is correct:
1
2
3
4
5
6
struct LectureInfo
{
string name;
};

LectureInfo dayang = {"Testing"};


In order to get the error cannot convert char* to LectureInfo, i think the original posters real code actually looks like this (notice the lack of braces):
1
2
3
4
5
6
struct LectureInfo
{
string name;
};

LectureInfo dayang = "Testing";
Last edited on
Topic archived. No new replies allowed.