문제

How can I print a text for instance programming language without double quotes and apostrophes in source code? I made in c++ :

#include <iostream>
#define Rep(x) #x
int main()
{
   printf(Rep(programming language));
   return 0;
}

Program is ok but I wonder if there is another way to do this? and how do it in java? is any possibility do it in java?

도움이 되었습니까?

해결책

Insert code units as integer literals:

#include <iostream>

int main() {
    char[] string = { 0x41, 0x42, 0x43, 0x0A, 0x00 };
    std::cout << string;
}

In Java this should do:

byte[] bytes = {(byte)0x41, (byte)0x42, (byte)0x43, (byte)0x0A};
String string = new String(bytes, "UTF-8");

다른 팁

The best way to avoid placing string literals in your code is to use a file to read them from. Note: you should consider clarity when looking at alternatives. Ask yourself how is

Rep(programming language)

clearer/betters than

"programming language"

BTW: if you want to make your code unreadable, you can do this in Java

String s = \u0022programming language\u0022
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top