-
specific length
Hi, i was wondering how i could specify the length of something in a console program like:
Code:
#include <iostream.h>
#include "apstring.h"
int main()
{
apstring state;
cout << Which state do you live in?
cin >> state;
cout state;
}
How would i make it so state was two letters as in AZ or CA?
thanks!
-
cin.getline(string, 3, '\n');
Tis what I meant :)
-
This person should get a cookie for using the code tags (joke from a friend)
but back to the point....use chars.
char[2];
//insert code here.
that should work (no need for code, ain't posting it)
-
i believe getline would need 3 instead of 2, because it reserves a spot for the null character
-
i think he meant
cin.getline(state,3);
-
if you're working with state abbrev. you probably need a data table with state names to abbrev. the first two or three letters of any state should suffice. (except for mississippi and missouri.)