You can use std::noskipws to disable the whitespace skipping that std::cin does by default:
#include
#include
int main() {
char c;
std::cin >> std::noskipws;
while (std::cin >> c) {
if (c == ' ')
std::cout << "A space!" << std::endl;
}
return 0;
}
sir jee but there's a prob.. u r not holding a string at whole.. what we need is that we can play with the whole string including spaces.. what u r doing is just taking one cahracter at a time.
ReplyDeletefor strings you can use fgets function and check for newline character at the 0th index of the string inputted
ReplyDeletewe can try getline function too..
ReplyDeletegetline(string,cin,delimeter);