How to display "" itself as a string
Is there any way "" (double quotes itself) can be displayed as a string in c++
I tried cout &l开发者_如何转开发t;< " "" ";
which obviously does not work.
You need to escape them with '\' inside your string:
cout << " \"\" "
You need to escape your string.
cout << " \"\" ";
You need to escape your string, for example:
#include <iostream>
using namespace std;
int main()
{
cout << " \"\" ";
}
Output:
""
The two easiest ways I know of are as an escaped value in a string:
cout << "\"";
and as a character:
cout << '"';
I generally prefer the latter, as emacs's C++ mode colorizes it better. If you use the former, it gets confused and thinks everything after the third quote is inside a string. It is (debatably) less confusing for humans too.
精彩评论