Cannot say hello to the world due to 'code 1'
/************************************************************
* * Project 0: My First Program in C++ * * Author: xxx xxxx * Date: 18 January 2015 * * This is the canonical first program for C++. * Its purpose is to show that one knows how to create a program in * one's particular programming environment. * ************************************************************/ #include <bjarne/std_lib_facilities.h> int main() { cout << "Hello, world!\n"; return 0; } I compiled the hello world program as my prof instructed. then I used C+c C+c, delete 'make -k' and replaced with 'g++ -o proj0 -std=c++11 proj0.cc', choose to save the file, and it goes 'compilation exited abnormally with code 1' note that I do all these by making SSH connection with computer in lab with a linux system :) FYI, the whole thing is: -*- mode: compilation; default-directory: "~/private/cs1/proj0/" -*- Compilation started at Sun Jan 18 21:15:54 g++ -o proj0 -std=c++11 proj0.cc In file included from /usr/include/c++/4.9.2/locale:41:0, from /usr/include/c++/4.9.2/iomanip:43, from /usr/local/include/bjarne/std_lib_facilities.h:220, from proj0.cc:14: /usr/include/c++/4.9.2/bits/locale_facets_nonio.h:1869:5: error: template-id do_get<> for String std::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const does not match any template declaration messages<char>::do_get(catalog, int, int, const string&) const; ^ /usr/include/c++/4.9.2/bits/locale_facets_nonio.h:1869:62: note: saw 1 template<> , need 2 for specializing a member function template messages<char>::do_get(catalog, int, int, const string&) const; ^ Compilation exited abnormally with code 1 at Sun Jan 18 21:15:55 |
I don't exactly understand if you are a beginner in C++ why do you have to code like that?
Most importantly .h type headers are not encouraged in C++ especially when you are using 2011 standard. It might be so that the iostream is not included. Please try the following code: Code:
/************************************************************ |
Well, this works for me:
Code:
#include <iostream> For some odd reason it required me to add the "std::" before the cout call which led me to re-check that cout is part of iostream. It is. I then further commented out the include file and it didn't compile. I've done C++ sparingly and do understand that it sometimes requires the declaration of the top level group, or section to use a library function, but if the include directives are properly used, then you don't need to do that. But to me the points to consider are the following:
|
Quote:
cout is in std namespace and instead of the syntax that you provided above one can also add the follwing lines: Code:
using namespace std; Finally I would agree with the fact that the program shown could have been coded in a better way. You really need to use std_lib for this. |
All times are GMT -5. The time now is 10:02 PM. |