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

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.

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 see edit.
2 str.length() will give you the length of the string called str. You have no such string.
3. google.

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];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.