【问题标题】:error: ‘string’ undeclared (first use in this function) gcc OS X错误:“字符串”未声明(在此函数中首次使用)gcc OS X
【发布时间】:2013-03-21 07:02:46
【问题描述】:
$gcc a.c

string s = "string";

a.c:4: error: ‘string’ undeclared (first use in this function)


$gcc -v

Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

【问题讨论】:

    标签: c macos gcc


    【解决方案1】:

    C 中没有 string 数据类型。

    你可能想使用:

    const char* s = "string";
    

    【讨论】:

      【解决方案2】:

      C 中没有String 这样的数据结构。我们用作字符串的通用术语实际上是一个以\0 结尾的字符数组。

      这就是你可以做的事情

      char *s = "string"
      

      也许

      char s[]="string"
      

      【讨论】:

        猜你喜欢
        • 2016-05-09
        • 2018-10-03
        • 1970-01-01
        • 2015-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多