Error compiling when including tr1/memory

Hello,

I have got a strange error with a very simple code :

#include <tr1/memory>

int main(){
return 0 ;
}


The error is :

command-line:0:5: error: expected ']' before numeric constant
/sources/main.cpp:5:1: error: expected identifier at end of input
}
^
/sources/main.cpp:5:1: error: expected unqualified-id at end of input
/sources/main.cpp:5:1: error: expected '}' at end of input

I had made the test without "#include <tr1/memory>" and it works just fine. As I need it later, I wonder how I can do.

Can you help me please?
Thanks.
Hi
first use code option to post code section. this lead to answering easy for others and good for reading.

say way of compilation, in terminal.

finally your answer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/*

compile ::: $ g++ test.c -o test

run :::    $ ./test

*/


#include <tr1/memory>

int main(int argc,char **argv){
	
	return 0 ;
}


if not work try:
 
g++ test.c -o test -std=c++98
Since it is now 2017, why don't you leave behind the old C++0x TR1 in favor of the standard version? If you do not have support, it is time to update your compiler.
Last edited on
this is only an example for better compatibility to compile code.
i said can be compile that code without any extra compiler flag.
but your suggestion is good thanks mbozzi.
@eec

compile at least with :

g++ -std=c++14 -Wall -Wextra -pedantic-errors

I routinely compile with these other options as well:

http://www.cplusplus.com/forum/general/183731/#msg899203

These problems are very common and I recommend detecting them as quick as possible. You can help from programs like checkmarx or others but it's always recommended to try and it on your own.
Good luck!
Ben.
Topic archived. No new replies allowed.