dyl4n130
dyl4n130

Reputation: 61

(C++) Taking each char of a string and putting it into an array and getting the size of said array?

cout << "Input text:\n";
cin >> tex;

take tex and put it into an array of whatever size?

for example, if I inputted "hello", get an array that is something like

array[x] = {'h', 'e', 'l', 'l', 'o'}

I would then have a for loop that performs something on each letter (which I know how to do) but then how do I make it stop at the end?

Upvotes: 0

Views: 56

Answers (1)

Sumeet
Sumeet

Reputation: 190

for a standard string, use below.

cout << "Input text:\n";
cin >> tex;
for(std::string::iterator it = tex.begin(); it != tex.end(); ++it) {
    //your work
}

or

for (int i = 0; i < tex.size(); i++){
    cout << tex[i];
}

Upvotes: 1

Related Questions