I have not used a char array in close to two years. I also have not coded in C++ in a while so I think I keep making dumb mistakes. I am just practicing converting char array to strings now.
I was running a few tests cases and I don't understand why some cases work and a couple do not.
I was trying to convert a string to a char array and I was trying to get the first 4 chars of a string and store it in a char array of size 4.
First off, why does this not work?
char testA[4];
testA[0] = "a";
It gives me an error in VS.
Next why does this work if the above case doesn't?
for (int i = 0; i < line.size(); i++) {
testA = line;
}
If I do this below, it will give me the first 4 characters but then more characters of gibberish behind it?
cout << testA <<endl;
I was running a few tests cases and I don't understand why some cases work and a couple do not.
I was trying to convert a string to a char array and I was trying to get the first 4 chars of a string and store it in a char array of size 4.
First off, why does this not work?
char testA[4];
testA[0] = "a";
It gives me an error in VS.
Next why does this work if the above case doesn't?
for (int i = 0; i < line.size(); i++) {
testA = line;
}
If I do this below, it will give me the first 4 characters but then more characters of gibberish behind it?
cout << testA <<endl;