开发者

How to display "" itself as a string

开发者 https://www.devze.com 2023-03-26 18:46 出处:网络
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 \'\\\' i

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消