0

I know this program only takes few lines.
I don't now how to out put the text to print every other letter

for example: shsofwbanrqeiyzobu
output: h o w a r e y o u

int main()
{string k;
    cout << "eneter a text" << endl;
    getline(cin,k);

    for(int index =1; index <=(int)str.length(); index+=2)
{

    

}

any help is appreciated

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by myrongainz
0

1 Where are your #includes and namespace?
2 What is str.length (why would that give you the size of k)?
3 Where is your output line?
EDIT If this is a snippet ignore 1, if not you need to check your braces and there is no return statement.

Edited by frogboy77: n/a

0

1 Where are your #includes and namespace?
2 What is str.length (why would that give you the size of k)?
3 Where is your output line?

1 - i have that; i just didn't copy that part since i didn't find it necessary. i do have #include <string>

2 - str.length is something a friend of mine had in a program similar to this...

what would you suggest i rather include.

3 - that's the reason i made the thread. I don't know how to cout it

1

1 see edit.
2 str.length() will give you the length of the string called str. You have no such string.
3. google.

0

1 see edit.
2 str.length() will give you the length of the string called str. You have no such string.
3. google.

k thanks

your second statement helped me out


cout<<k[index];

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.