c - 在 C 中使用 string.h 字符串对象时出错

标签 c linux string gcc

在 cmd 中,我输入:gcc -v 来获取我的编译器版本,这就是我得到的

C:\Users\myStuff\Documents\C_Codes>gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.8.1/configure
--prefix=/mingw --host=mingw32 --build=m ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++ ,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld -- with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable- libgomp --enable-threads --with-libiconv-prefix=/mingw32
--with-libintl-prefix=/ mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T Thread model: win32 gcc version 4.8.1 (GCC)

我查看了 c:\minGW\include\以尝试找到 string.h 并且它在那里但是当我尝试让我的 C 代码类似于:

字符串温度

我得到以下编译错误:

错误:未知类型名称“string”

我该如何解决这个问题以便我可以使用字符串??

我还包含了stdio.h、stdlib.h,还有两个字符串头,string.h和strings.h

最佳答案

尝试使用g++编译代码,因为c语言不支持string类型,否则你可以使用字符数组相同。

您可以像这样定义字符数组并将内容复制到数组中

char arr[SIZE];
strcpy(arr,"Your String");

关于c - 在 C 中使用 string.h 字符串对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624109/

相关文章:

c - 当我创建并向结构添加值时发生了一些事情,导致了段错误

python - ctypes 上的 PyObject_Str 段错误通过了字典

linux - 更改运行 Angstrom Linux 的 BeagleBone UART0 的波特率

python - 使用 Python 创建的文件被写入错误的目录

c - Linux : close or redirect standard output to/dev/null after detaching from terminal

java - 无法让字符串compareTo方法工作

c - 验证来自内核的文件数字签名

无法理解 c 中二维数组中的寻址

c++ - strcmp() 可以在 C++ 中处理字符串吗?

java - 将字符串转换为套接字