c++ - Read an ifstream word for word into char* -


just trying programming test fun. stipulates should read each word of file, 1 one.

it hints might want use ifstream, won't let me use std::string, looks have use char*

in c read line line & use strok() have multiple delimiters (white-space, quotes, brackets, etc).

what c++ way - words 1 one - without using std::string ?

first must make sure have memory allocated string (this part handled automatically std::string). use normal input operator >>, separate on whitespace.

don't forget free memory allocate (also handled automatically std::string).

lesson learned: use char pointers exercises these, otherwise use std::string.


Comments

Popular posts from this blog

xslt - Substring before throwing error -

Google Cloud Bigtable Durability/Availability Guarantees -

php variable $_SERVER['SERVER_ADDR'] is blank when using crontab -