is there a way to use cin.getline() without having to define a char array size before hand?

Posted by zebraman on Stack Overflow See other posts from Stack Overflow or by zebraman
Published on 2010-04-02T23:10:14Z Indexed on 2010/04/02 23:13 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

Basically my task is having to sort a bunch of strings of variable length ignoring case. I understand there is a function strcasecmp() that compares cstrings, but doesn't work on strings. Right now I'm using getline() for strings so I can just read in the strings one line at a time. I add these to a vector of strings, then convert to cstrings for each call of strcasecmp(). Instead of having to convert each string to a cstring before comparing with strcasecmp(), I was wondering if there was a way I could use cin.getline() for cstrings without having a predefined char array size. Or, would the best solution be to just read in string, convert to cstring, store in vector, then sort?

© Stack Overflow or respective owner

Related posts about getline

Related posts about cstring