samedi 3 février 2018

C++ input output

I saw two codes and was wondering why one should work and the other not....thanks in advance..

I know it's a really simple question but thanks for your time

#include <iostream>
using namespace std;
#include <cstring>
const int STR_LIM = 50;
int main()
{

char word[STR_LIM];
cout << "Enter word, to stop; press the word done" << endl;
int Count = 0;

while (cin >> word && strcmp("done", word))
    ++ Count;
cout << "You entered a total of " << Count << " words. \n";


return 0;
}

And:

#include <iostream>
using namespace std;

int main()
{
int i = 0;
char word[256];

while(cin >> word != "done")
    ++i;

cout << i;

}

Aucun commentaire:

Enregistrer un commentaire