What is VacationLocation[10]? A character or a pointer-to-character (i.e. pointing to a c-string)?
Are you trying to append (concatenate) a string to another existing string? Can you explain more in detail of what you're actually trying to accomplish?
I suggest using std::strings instead, it will take care of so much for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Example program
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> VacationLocations = { "KIVU", "LAKE VICTORIA", "PRIPYAT" };
VacationLocations.push_back("LAKE GENEVA");
VacationLocations[3] += " APPEND";
for (size_t i = 0; i < VacationLocations.size(); i++)
{
std::cout << VacationLocations[i] << '\n' ;
}
}
Im trying to initialize a struct char array:
struct PurchaseInfo
{
char CustomerName[50];
char VacationLocation[30];
int SeatNumber;
char SeatAlphabet;
char CustomerReferenceCode[10];
char DepartDate[50];
char ReturnDate[50];
}MAX[100];
in one of my function, im trying to initialize MAX[counter].VacationLocation[30] with the string "the name of location". i tried to use strcpy but it shows error "invalid conversion from char* to const char or something like that.
i also tried to initialize the char MAX[counter].SeatAplhabet with 'A' using strcpy(MAX[counter].SeatAlphabet,'A') .......... but it shows error--
error: invalid conversion from 'char' to 'const char*' [-fpermissive]|
you can use strcpy, you did something wrong. the loop works too, but you should revisit the strcpy as it is the right way to do it and looping every string in your class is going to bloat everything badly if you don't compact it.
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <cstring>
usingnamespace std;
int main()
{
char result[100];
strcpy(result, "happy place");
cout << result << endl;
}