0

Hi all!!!
I'm starting to learn C++ on my own and I have a question about accessing a structure through a dynamic array. I've looked into some previous threads that apply to this but they all deal with structure composed of int variables. This concerns char and is driving me nuts.

#include <iostream>
using namespace std;

struct structname
{
   char pst[10];
};

int main(void)
{
   structname *pointername = new structname[3];
   pointername[0].pst = "Mocha";
   cout << pointername[0].pst << endl;
   delete pointername;   
   return 0 ;
}

I've attempted these syntaxes but to no avail
structname->membername=
(*structname).membername=
(structname).membername=

all I get is error message about const char* not being able to be converted to char.
Thanks for any help.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by hacker9801
0

Use std::string pst instead of char pst[]. Or you have to use strcpy() to assign a value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.