sdl을 공부하려고 튜토리얼을 들여다보다가 'std::string'을 발견했습니다. 여기서 'std'가 무엇인지 알고 싶습니다.

HotPotato의 이미지

포럼에서 검색한 결과, 그리고 '::'가 있는 걸로 봐서 cpp와 관련이 있는 듯 싶은데요.
멤버함수도 아니고, 그렇다고 std.h가 있는 것도 아닌데.. 궁금한 것이 많이 생기네요.

튜토리얼 예:

SDL_Surface *load_image( std::string filename ) 
{ //Temporary storage for the image that's loaded

그리고 아래에서도

//The headers 
#include "SDL/SDL.h" 
#include <string>

'string'을 바로 읽어들이는데, 'string.h'가 아니네요?

코드 발췌 URL : http://lazyfooproductions.com/SDL_tutorials/lesson02/index.php
--
사회나와서 바로 접한 언어가 자바다 보니 개인적으로 약한 C기초문법 만으로는 제대로 된 소스조차 만져본 적 없는
CPP 공부할 때 뇌가 비어있는 듯한 느낌을 받는 것 같습니다.

IDNed의 이미지

일단 헤더는 string이 맞습니다. 표준상에서 구현된 바로는 C++는 기존의 C 헤더를 포함해 모두 .h를 쓰지 않습니다.

(C 헤더의 경우는 앞에 접두사 c를 쓰죠. 예를 들어 #include <cstdio>)

그리고 그러한 표준상의 내용(역시 C 라이브러리 포함)은 모두 std 네임스페이스에 들어가게 되어 있습니다. 그래서 std::를 쓰는 것입니다.

네임스페이스에 대한 개념은 Effective C++ 등 여러 책을 보시거나 정 안되면 구글신께 부탁드리면 나올 겁니다 ;)

zelon의 이미지

간단히 설명드리자면 name space - 이름 공간입니다. 왜 이런 이름 공간이 필요하냐면, 배운대로 말씀드려서 '잘 쓰이는 이름은 중복될 경우가 많고, 보다 명확히 구분이 필요해서' 입니다.

예를 들어, string 이라는 class 는 여러 라이브러리에서 많이 쓸 만한 클래스 이름입니다. 그런데 A, B 라는 2개의 라이브러리에서 둘다 string 이라는 클래스가 정의되어 있는데, 공교롭게도 이번에 진행 중인 프로젝트에서는 A, B 이렇게 2개의 라이브러리를 둘다 써야합니다. 그런데 그냥 string 이라고 하면 어느 라이브러리의 string 인지 모르겠죠. 그래서 A::string, B::string 이렇게 구분해서쓸 수 있는 겁니다. name space 가 없다면 당장 string 부분에서 redefine 에러가 나겠죠.

여담으로 요즘의 멋진 통합 개발 환경에서는 name space 를 통해서 클래스 이름등을 쉽게 찾는데 쓰이기도 합니다 :)

http://www.wimy.com

-----------------------------------------------------------------------
GPL 오픈소스 윈도우용 이미지 뷰어 ZViewer - http://zviewer.wimy.com
블로그 : http://blog.wimy.com

HotPotato의 이미지

그럼 아래는 구글에서 찾은 소스인데..

#include
using namespace std;

However, you might reconsider using the whole namespace. Why not just the
items you need, like this:

#include
using std::cout;
using std::cin;
using std::endl;

이게 C#의 문법이 아니고 C++의 문법이었군요. 자바의 'import x.x.x' 형식을 닮아서 자바를 본 딴 C#인 줄 알았거든요.
답변해주신 두 분 모두 감사합니다.

--
즐 Tux~

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.