簡體   English   中英

C 是否支持原始字符串文字?

[英]Does C support raw string literals?

C++11 添加了對原始字符串文字的支持,例如:

R"foo(A " weird \"
 string)foo"

C有這種東西嗎? 如果是,在什么版本的標准中? C11? 如果沒有,有沒有人知道它是否正在計划中以及是否有任何編譯器支持它?

C有這種東西嗎? 如果是,在什么版本的標准中? C11?

C(C90、C99、C11)不支持此功能或任何其他類似功能。

如果沒有,有誰知道它是否正在計划中

我不知道,但通常 C 委員會強烈反對在 C 中包含新功能。

如果有任何編譯器支持它?

我剛剛測試了它,它顯然支持最近的gcc版本作為 GNU 擴展(使用-std=gnu99-std=gnu11 )。

例如:

printf(R"(hello\nworld\n)");

編譯並給出預期的行為。

/// 我的經驗。 使用代碼塊,GCC MinGW。

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <windows.h>
///#include <threads.h>
#include <conio.h>
/// #include <dos.h>
#include <direct.h>

int main(void)

{
  printf(R"(.C with a Capital C file format does not support raw string )");
  printf("\n");
  printf(R"(.c with a small c file format does support raw string )");
  printf("\n");
  printf(R"( Raw string did not support \n new line )");
  printf("\n");

  printf(
      R"(More reading material at - https: // en.wikipedia.org/wiki/String_literal#Raw_strings;)");
  printf("\n");
  printf(
      R"(More reading material at - https: // en.wikipedia.org/wiki/String_literal;)");
  printf("\n");
  printf(
      R"(More reading material at - https://stackoverflow.com/questions/24850244/does-c-support-raw-string-literals;)");
  printf("\n");
  printf(
      R"(More reading material at - https: // docs.microsoft.com/en-us/cpp/c-language/c-string-literals?view=vs-2019)");
  printf("\n");
  printf(
      R"(More reading material at-https: // docs.microsoft.com/en-us/cpp/c-language/string-literal-concatenation?view=vs-2019)");
  printf("\n");
  /// Raw string.

    printf(R"(More reading material at - https://www.geeksforgeeks.org/const-qualifier-in-c/;)");
  printf("\n");
  
  
  return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM