c++ include 문장에 문제가 있나요?

Iinux의 이미지

리눅스에서
소스코드를 다운받아서 컴파일 해보고 있는데요
아래와 같은 오류가 발생합니다.

unix/src/fileselector.cpp:92: error: 'strncpy' was not declared in this scope
unix/src/fileselector.cpp:93: error: 'strcat' was not declared in this scope

아시다시피 오류가 발생하는 함수는 string.h 파일에 정의되어 있는것인데요
소스코드에 보면 #include <string> 이라는 문장이 있습니다
(#include <string.h> 가 아니라..)

그래서 string.h 로 바꿔서 include 하면 컴파일이 정상적으로 됩니다..
이런 소스가 한두개가 아니라서..일일이 바꾸려니 좀 짜증나네요

c++에서는 #include <string> 이런 문법이 혀용되는 것으로 알고 있는데
왜 안되는 것이죠?

컴파일할때보니 g++ 로 소스를 컴파일하고 있습니다.

kang1의 이미지

using namespace std;
하거나

std::strcpy 해보세요..

---

대한민국

죠커의 이미지

잘못된 코드가 아닌가 생각됩니다.

strncpy 등의 C 언어 함수들은 string.h와 cstring에 들어있습니다. string은 C++의 문자열을 다루는 템플릿 객체를 다루고 있습니다.

- 죠커's blog / HanIRC:#CN

klyx의 이미지

string 해더파일은 .h를 생략한게 아니라, string.h와는 전혀 별개의 해더파일입니다.
해당 컴파일러의 해더파일을 찾아보시면 string이라는 파일과 string.h라는 파일이 모두 존재하는 것을 알수 있을 것입니다.

Scarecrow의 이미지

string이 아니라 cstring으로 해야 합니다.

Iinux의 이미지

흠.. 약간 혼란이 생기네요
string( string.h가 아니라)은 어디에 있는지요.
그리고 거기에 strncpy 함수도 있나요?

또 cstring 는 어디에 있나요? 여기에도 strncpy 같은 함수가 있나요?
/usr/include, /usr/local/include

제가 직접 파일을 열어보고 싶은데요.. 이 폴더말고 다른 폴더에 있나요?

지금은 회사라서.. 제 리눅스에 접속을 못하는 중이네요

=====================

=====================

myueho의 이미지

C에서 string.h 역할을 C++ 에서 cstring 이 합니다. 물론 string.h도 사용할 수 있습니다.
말씀하신 strncpy는 string.h 에 선언되어 있습니다.

string 은 C++의 basic_string Class 가 정의되어 있는 파일입니다.

hys545의 이미지

즐린

c++전용 헤더 파일은 이 밑에 있더군여

즐린

Iinux의 이미지

감사합니다.
C언어밖에 안해봐서.. 엄청 삽질하네요 ㅠㅠ

=====================

=====================

죠커의 이미지

제대로된 C++ 서적을 한번 보시는 것이 좋지 않을까 합니다. :)

- 죠커's blog / HanIRC:#CN

댓글 달기

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