cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How to store a string into a vector?
How to store a string into a vector?
Apr 22, 2016 at 5:01am UTC
stealthboy
(44)
Given a string such as this:
These,Are,The,Words,To,Store
How could I make a vector that stores each word as a string, separating them into elements determined by the commas? aka, 'These' would be stored in 0, 'Are' stored in 1, etc.
Thank you for any help.
Apr 22, 2016 at 10:38am UTC
coder777
(8444)
There are several ways to do that.
You can use the function find() and substr(). See:
http://www.cplusplus.com/reference/string/string/?kw=string
Or you can use stringstream. See:
http://www.cplusplus.com/reference/sstream/stringstream/?kw=stringstream
In order to get the word and store them in a vector (with push_back()). See:
http://www.cplusplus.com/reference/vector/vector/?kw=vector
Topic archived. No new replies allowed.