cin.get

I tried to introduce a cin.get instruction into a do-while and it didn't work.Can you help me?This is the actual code:


#include<string.h>
#include<iostream>
using namespace std;
int main()
{int n,b,i,j,k;
char a[100];
do{
cin.get(a,100);
n=strlen(a);
if(n<3)cout<<"Introduce a string with more than two digits!"<<endl;
}
while(n<3);
while(n>2 || n>1)
{for(i=0;i<=n-1;i++)
a[i]=a[i+1];
n=n-2;
for(k=0;k<=n-1;k++)
cout<<a[k];cout<<endl;}
return 0;
}

Only the do-whil instruction ins't working.The rest o fthe program does work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    const int MAX_CHARS = 100 ;
    const int MIN_CHARS = 3 ;
    char cstr[MAX_CHARS] ;

    // http://www.cplusplus.com/reference/istream/istream/getline/
    // http://www.cplusplus.com/reference/istream/istream/gcount/
    while( std::cout << "please enter a string with at least " << MIN_CHARS << " characters: " &&
           std::cin.getline( cstr, MAX_CHARS ) &&
           std::cin.gcount() <= MIN_CHARS ) std::cout << "that string is too small.\n" ;

    std::cout << "you entered '" << cstr << "'\n" ;
}
Topic archived. No new replies allowed.