0

For some reason, the code compiles on Windows but not on macOS. The issue appears to be a raw string literal that I was using so that I could write a multi-line string.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string test = R"(
        This is a 
        test string.
    )";
    cout << test << endl;
}

I get the following error after attempting to run this file:

error: use of undeclared identifier 'R'
    string test = R"(
genpfault
  • 51,148
  • 11
  • 85
  • 139
djhe
  • 1
  • 4
    You need to enable C++11 mode or newer when you compile. – NathanOliver Oct 19 '22 at 20:04
  • Thanks for your reply. Would you happen to know how to do this when running this file in VSCode on macOS? I am using a machine with Apple Silicon if it makes a difference. When I click "Run" on the menu bar and then "Run without debugging" I am given multiple compilers to choose from such as 'clang++' and 'g++' but none work for some reason whereas on Windows they work right away. – djhe Oct 19 '22 at 21:06
  • ***but none work for some reason*** The default on macOS for some reason is prior to c++11. – drescherjm Oct 19 '22 at 21:20
  • Just wanted to add. I was able to get this working in xCode with no issues or special configurations. For some reason, VsCode or attempting to compile the cpp file in the terminal will give me the error. I have run "g++ -v" in my terminal and the output I get is: "Apple clang version 14.0.0 (clang-1400.0.29.102)" – djhe Oct 19 '22 at 21:20
  • ***VsCode or attempting to compile the cpp file in the terminal will give me the error.*** The official VSCode documentation tells you how to fix that here: [https://code.visualstudio.com/docs/cpp/config-clang-mac](https://code.visualstudio.com/docs/cpp/config-clang-mac) note the 2 places in the 3 json files where you have to add a setting for `c++17` support. – drescherjm Oct 19 '22 at 21:22

0 Answers0