Reputation: 1
In the college I saw that my teacher made a program making a struct just like this:
#include <iostream>
using namespace std;
struct string_
{
char _string [255];
}
struct person
{
string_ birthday[5];
string_ name[5];
}x;
I think that he did it because it seems to be easier to manipulate the strings in that way... The problem came when I did an exam just in that way and he said that it was unnecesary
How can I save the strings not doing that and not using the datatype "string". something like...?
#include <iostream>
using namespace std;
struct person
{
char birthday[5][255];
char name[5][255];
}x;
Upvotes: 0
Views: 76
Reputation: 744
It may be because you cannot return array (char[255]
) in a function, but you can return a struct, that contains an array.
For example
char[255] foo(); // cant do that
char* foo(); // can do that, but instead of copying string, only pointer to its begining is returned
string_ foo(); // can do that, and whole struct, that contains char[255] will be copied (returned)
Upvotes: 2