U
Usenet Text
I am a C++ newbie and am a little confused on CString arrays. I wrote an
example below of what I am trying to do below. It seems that if I enter in a
model number like A123 or B345, that when the cout statement comes around
that it only outputs the first character. Is there no way to do this with
type char and have the cout output the entire 4 character model number? If
not would the only choice be a type string? I want to do an input validation
on each character (isdigit, isalpha and strlen) so that is why I am trying
to make it a char type. Thanks for any input .
#include <iostream>
using namespace std;
char modelNum[4];
int main ()
{
for (int index = 0; index < 4; index++)
{
cout << "Please enter a model number " << endl;
cin >> modelNum[index];
cin.ignore(4);
}
for (int IDX = 0; IDX < 4; IDX++)
{
cout << modelNum[IDX] << endl;
}
return 0;
}
example below of what I am trying to do below. It seems that if I enter in a
model number like A123 or B345, that when the cout statement comes around
that it only outputs the first character. Is there no way to do this with
type char and have the cout output the entire 4 character model number? If
not would the only choice be a type string? I want to do an input validation
on each character (isdigit, isalpha and strlen) so that is why I am trying
to make it a char type. Thanks for any input .
#include <iostream>
using namespace std;
char modelNum[4];
int main ()
{
for (int index = 0; index < 4; index++)
{
cout << "Please enter a model number " << endl;
cin >> modelNum[index];
cin.ignore(4);
}
for (int IDX = 0; IDX < 4; IDX++)
{
cout << modelNum[IDX] << endl;
}
return 0;
}