g++ 로 컴파일을 하니...

kknd345의 이미지

vi 로 만든 hello.cpp인데요..

#include

int main()
{
cout << "Hello World!\n";
return 0;
}

컴파일을 하니...
밑에처럼 뜨길래...

[root@localhost c++]# g++ hello.cpp
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from hello.cpp:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples
include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning
use -Wno-deprecated.

이렇게 뜨길래요...
게시판 검색하니 iostream.h 에서 .h 빼서 하라길래.

#include

int main()
{
cout << "Hello World!\n";
return 0;
}

이렇게 컴파일 하니..

[root@localhost c++]# g++ hello.cpp
hello.cpp: In function `int main()':
hello.cpp:5: `cout' undeclared (first use this function)
hello.cpp:5: (Each undeclared identifier is reported only once for each
function it appears in.)

이처럼 아예 컴파일이 안 되는데 해결 방법 없나요?

jedi의 이미지

#include <iostream>
#include <string>

using namespace std ;

int main() 
{ 
  cout << "Hello World!\n"; 
  return 0; 
}

+++ 여기부터는 서명입니다. +++
국가 기구의 존속을 위한 최소한의 세금만을 내고, 전체 인민들이 균등한 삶을
영위할 수 있는 착취가 없는 혁명의 그날은 언제나 올 것인가!
-- 조정래, <태백산맥> 중에서, 1986년

kknd345의 이미지

[root@localhost c++]# g++ hello.cpp
hello.cpp: In function `int main()':
hello.cpp:6: `cout' undeclared (first use this function)
hello.cpp:6: (Each undeclared identifier is reported only once for each
function it appears in.)

적어준 대로 작성했는데도 이렇게 나오는군요...

1%의 가능성이면 충분하다!
최선을 다하자!

eminency의 이미지

음, 제가 보기엔 안 될 리가 없는데요? -_-;;

'cat hello.cpp'의 결과도 올려주시는게...

노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5

eungkyu의 이미지

kknd345 wrote:
[root@localhost c++]# g++ hello.cpp
hello.cpp: In function `int main()':
hello.cpp:6: `cout' undeclared (first use this function)
hello.cpp:6: (Each undeclared identifier is reported only once for each
function it appears in.)

적어준 대로 작성했는데도 이렇게 나오는군요...

$ cat hello.cpp
#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "Hello World!\n";
    return 0;
}

$ g++ hello.cpp
$ ./a.out
Hello World!
$

전 잘 되는데...
이상하네요. 저 코드가 컴파일이 안되다니...

kknd345의 이미지

잘 되네요...

using namespace std;

이걸 빼먹었습니다 ㅜ.ㅜ....

죄송..

그런데

#include<string>

using namespace std;
이 두줄 설명좀 해주세요.. 책에는 없으니깐 멀 뜻하는지 잘 모르겠어요..

1%의 가능성이면 충분하다!
최선을 다하자!

ssehoony의 이미지

과거 string.h 나 iostream.h 가
string 랑 iostream 으로 .h 없는 형식으로 헤더파일명이 변했습니다.
그러니깐 .h 를 이용하는건 구식이고 신식을 그냥 .h 없는 걸 include 해서
코딩하는거져

파일명을 변경한건 과거의 헤더파일과 구별을 명시적으로 하기 위함인것 같은데
서로의 차이점은
iostream.h 은 cout 을 그냥 사용하면 되는거고
iostream 은 std::cout 하는 식으로 std:: 라는 걸 넣어 주어야 합니다.

좀 더 원론적으로 말하면
"최근 C++ 표준 라이브러리는 모두 std 라는 네임스페이스 내에 두는걸 원칙한다."
라고 할 수 있져

네임스페이스(namespace) 라는건 일종의 묶음 같은건데요
이건 별도로 찾아보시면 using namespace std; 라는게
뭘 의미하는지도 아실 수 있을 겁니다.
책에 namespace 라는게 없다면 다른 좋은 자료 많으니깐 인터넷에서 찾아보세요.
참고 : http://cplusplus.com/doc/tutorial/tut5-2.html

std::cout 이 뭘 의미하는지 이해하실려면 우선 namespace 에 대해 공부하시면 알게 되는 내용입니다.

맹고이의 이미지

책에 그런 내용이 없다면

그 책은 버리시고

딴 책 보세요...

죠커의 이미지

iostream.h를 쓰고 using namespace std를 안 쓰는 책이라면 맹고이님의 말대로 버려도 무방합니다. c언어 책이라면 flush(stdin)이 있다면 버려도 되구요.

그리고 이상하게 안 쓰시는 분들도 많은데 c++에서는 c 해더들도 래핑해서 std 안에 두고 있습니다. stdio.h 해더는 cstdio 이런 식으로 .h를 때고 앞에 c를 붙여두고 있지요.

envia의 이미지

CN wrote:
c언어 책이라면 flush(stdin)이 있다면 버려도 되구요.

여기에는 무슨 문제가 있는지 알려주시면 고맙겠습니다. (__)

----

It is essential, if man is not to be compelled to have recourse, as a last resort, to rebellion against tyranny and oppression, that human rights should be protected by the rule of law.
[Universal Declaration of Human Rights]

envia의 이미지

아... 표준에 정의되지 않은 것이군요. :oops:

감사합니다.

----

It is essential, if man is not to be compelled to have recourse, as a last resort, to rebellion against tyranny and oppression, that human rights should be protected by the rule of law.
[Universal Declaration of Human Rights]

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.