Exiting a while(cin>>..) loop

Hello everyone, I wrote the following code and can´t exit the while(cin>>buf) loop through the command prompt,I tried pressing the enter button but didn´t work can you please help me:

#include <iostream>
using namespace std;

struct par{
char* name;
int val;
};

const int large=1024;

static par vec[large+1];

par* find(const char* p){
int i;
for(i=0;vec[i].name;i++)
if(strcmp(p,vec[i].name)==0) return &vec[i];
if (i==large) return &vec[large-1];
return &vec[i];
}

int& value(const char* p)
{
par* res = find(p);
if(res->name == 0){
res->name = new char[strlen(p)+1];
strcpy(res->name,p);
res->val=0;
}
return res->val;
}

const int MAX = 256;

int main()
{
char buf[MAX];

while(cin>>buf) value(buf)++;

for (int i=0; vec[i].name; i++)
cout << vec[i].name<<":"<<vec[i].val<< '\n';
}
That operator>>() overload only returns false when the user's input cannot be converted to the type of the right hand operand. Since every user input can be converted to an array of characters, the overload will never return false.
I think sending EOF might work. Try hitting CTRL+Z or CTRL+D.
Topic archived. No new replies allowed.