The following code doesn't work. Why?

#include
#include
#include
using namespace std;
int main() {
char str[1000];
getline(cin, str);
char * ptr;
ptr = strtok(str, " ");
while(ptr != NULL){
cout<<ptr;
ptr = strtok(NULL, " ");
}

return 0;

}

getline(cin,str) is for string not for char array
use
cin.getline(str,1000)