Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
Aug 6, 1999

Copying a String Object to a Vector

Although the string class is very convenient for most string manipulation operations, it may be necessary sometimes to copy the contents of a string to a different container, e.g., in order to transmit the string to a remote host. You can copy the contents of a string to a vector of chars like this:

 
#include <string>
#include <vector>
using std::string;
using std::vector;
int main()
{
  string musical = "Cats";
  vector<char> vc (musical.begin(), musical.end());  //1
}

In the line numbered (1), a vector of char is initialized with the contents of the string 'musical'.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date