inhaler inhaler - 1 year ago 118
C++ Question

Checking empty string with c++

#include <iostream>

#include <stack>

#include <map>

#include <string>

using namespace std;

int main()

string a;


return 0;


I have really hard time to get this..if my input is nothing,i mean "Enter button"(means empty string,whitespaces),how to detect it with c++ language.Example is this can i print "I" if it is a empty string & how it works ?
Thanks in advance

Answer Source

If you want an empty input to be accepted you have to tell the input stream to not skip whitespace using the noskipws IO manipulator:

cin >> noskipws >> a;

Your code should then work as you want it to.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download