How do I turn a string word into letters?

So I'm having trouble trying to turn a word into letters. I've seen other posts but they deal with a sentence and it only outputs the words only. What I want to know is how do they take a word (Ex: "word") and break it into individual letters, where I want to store them in a vector of string?

If it's not too much trouble, I would prefer without using pointers or "std:: " marks, since I am trying to avoid pointers and I'm using "using namespace std" all the time. Thanks!

Ex:
In the example "word", it should output into:

"w"
"o"
"r"
"d"

and I will push them back into a vector of string where each vector element contains a letter.
Std or not:

1
2
3
4
5
6
string x = "word";
char a = x[0];
char b = x[1]; // and so on

char y[] = "word";
a = y[0];


Please don't store them in a vector.
It's a waste of memory and std::string is a char vector.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <vector>
using namespace std;


int main( void ){
	vector<string> word;
	string str = "hello world";
	vector<string>::iterator it;
	int i;
	
	for( i=0; i< str.length(); i++ ){
		word.push_back( string(sizeof(char),str[i]) ); // Convert char * to string
	}
} /* main() */


Although, I must agree with EssGeEich--strings may already be iterated through, so this isn't useful. Also, you mentioned converting the string into broken down strings, that is why the line in the for loop is more complicated.
Topic archived. No new replies allowed.