strings

I am writing a program that creates word search puzzles... i load the words from a file as a string into an array string words[k] i need to know how i can break these words down into their individual characters and also if i can measure how many characters are in the string is there some way that i can do this?
Yes you can break it down:

1
2
string me;
me = "Hello";


now me[0] will have a value of "H" and me[1] will have a value of "e" etc.

The size of the string is easy
1
2
3
string me;
me = "I want to now how many letters there are in this sentence";
cout << me.size();


Happy word searching!!

Quick note: In my example I mucked up - it would count the spaces
so what i would have to do is import the array with the string in it... take the element of the array i am using and set it to its own string... i dont have my laptop because i am on campus waiting for class so it would be like this i guess.

1
2
3
4
5
6
string stringstuffs(const string words[], const int i, int& size){//size is the size of the 
      string currentword; //word currently being worked with
      currentword = words[i];
      size=currentword.size();
      return currentword;
}

and that module would then give me the size by reference and the string class seems to just be an array anyways so i would have everything i need to go about putting the word in the puzzle character by character. Awesome man thanks i think the hardest thing i have to do now is test if the characters in the words match!
Last edited on
More info. on the string class:
http://cplusplus.com/reference/string/string/
Topic archived. No new replies allowed.