1

I'm Learning c++ , so pardon me I'm trying to store a Raw String in C++ but i get ‘R’ was not declared in this scope here is my code

#include <iostream>
#include <string>

int main()
{
    std::string nx =R"('(;<\"/  )3-)";
    std::cout << nx;
}

and Here is a online compiler which compiles it without any problem

probably its something with my compiler im on ubuntu 15.10 and latest g++

NikanDalvand
  • 77
  • 1
  • 9
  • It's because you only know how to enable C++14 via GUI. – LogicStuff Jan 25 '17 at 21:54
  • @LogicStuff Im Sorry I'm just learning , so dont know how to do it and i dont know what to search about it because when i searched for this type of problem i did not found anything useful or related – NikanDalvand Jan 25 '17 at 21:57
  • Raw Strings require C++11 or above; If you select option C++98 in the online compiler, then you will get the same error as with g++. How do you call g++? – Stephan Lechner Jan 25 '17 at 21:58
  • @stephan-lechner I started learning c++ so i use g++ test.cpp -o test – NikanDalvand Jan 25 '17 at 22:00
  • 1
    Try `g++ -std=c++11 -pedantic -Wall -Wextra test.cpp`. Also, don't call your test programs `test` because at some point you're going to confuse yourself and accidentally run the system `test` command instead, which produces no output. – melpomene Jan 25 '17 at 22:02
  • @melpomene thanks for your answer it works :) – NikanDalvand Jan 25 '17 at 22:10

1 Answers1

6

Raw Strings require C++11 or above; If you select option C++98 in the online compiler, then you will get the same error as with g++. See the following command for enabling C++11 in g++ (taken from this SO answer, please upvote when applicable):

$ g++ -std=c++11 your_file.cpp -o your_program
Community
  • 1
  • 1
Stephan Lechner
  • 34,891
  • 4
  • 35
  • 58