LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2015, 09:17 PM   #1
lckwswws
LQ Newbie
 
Registered: Jan 2015
Posts: 16

Rep: Reputation: Disabled
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
 
Old 01-19-2015, 03:57 AM   #2
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285
Blog Entries: 1

Rep: Reputation: 37
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:
/************************************************************
*
* 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>
#include <iostream.h>

int main()
{
     cout << "Hello, world!\n";
     return 0;
}
Please use standard techniques.
 
Old 01-19-2015, 01:45 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,102
Blog Entries: 10

Rep: Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524
Well, this works for me:
Code:
#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
    return 0;
}
I tried "<iostream.h>" and found that it rejected the .h extension.

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:
  1. First get the fundamental working, you don't need std_lib_facilities, be that your file or your instructor's file, or a general course include file; although it should not be a problem either. But to eliminate that, don't use it at first and then figure out if it happens to be a problem. AND just in counting lines from your post, it APPEARS that line #14 IS the std_lib_facilities include statement, so ...
  2. I have g++ version 4.6.3, I don't know what you have, but mine did not recognize the -std= argument whether I used a single dash or double dash, it just does not recognize that option in the form you have there. My compilation line was "g++ -o proj proj.cc" and that worked fine.
  3. If you can get it working, you should print out what you got working, you've obviously put in some effort to understand this, and then show it to the instructor and explain that you apparently typed it all in as per template or example and it didn't work; however you did get it to work by doing ... and show them the result where it did work.
  4. Because this appears to be introductory C++ and right at the start, they're basically supposed to give you examples that if you type them in correct and follow their instructions to the letter, they'll work.
  5. My points are that you're not far off here, whatever that include file is for std_lib_facilities, I'm betting you were instructed to put that line there, but it appears that it is part of the problem right now.
 
Old 01-19-2015, 02:23 PM   #4
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285
Blog Entries: 1

Rep: Reputation: 37
Quote:
I tried "<iostream.h>" and found that it rejected the .h extension.

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.
'.h' type of files, as I mentioned earlier are not preferable.
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;
-std is a valid option for passing the standard. You may check out the man page.

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pidgin Tencent QQ Chinese protocol help needed to code due to bug aquatooth Linux - Software 2 02-13-2011 11:57 PM
LXer: Microsoft: GPL Linux code release not due to violation LXer Syndicated Linux News 0 07-24-2009 04:40 PM
LXer: Ruby On Rails password protection can be nullified due to flawed code LXer Syndicated Linux News 0 06-06-2009 02:20 AM
Problem due to linking of an external compiled file to my code mk86 Linux - Newbie 1 04-28-2009 06:10 PM
Problem executing. This is not a due to code error :( estranged Linux - Software 2 09-06-2003 12:20 PM


All times are GMT -5. The time now is 12:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration