C中有字符串吗? [英] Is there string in C?
问题描述
CCS 中是否存在string
?
我可以使用:
Can I use:
string myString = "My String"; // Error
还是不是?
推荐答案
标准string.h
头文件 not 定义的数据类型为string
,它提供了处理C样式的功能字符串,它们是以null终止的字符数组.
The standard string.h
header file does not define a data type called string
, it provides functions for manipulating C-style strings, which are null-terminated character arrays.
例如,您可以执行以下操作:
For example, you can do something like:
#include <stdio.h>
#include <string.h>
int main(void) {
char *myName = "paxdiablo";
printf("Length of '%s' is %zu\n", myName, strlen(myName));
return 0;
}
请注意该代码中的字符串,它是指向paxdiablo
字符串文字的指针,不是标准未提供的某些string
类型.
Note the string in that code, it's a pointer to the paxdiablo
string literal, not some string
type that the standard does not provide.
C ++ 确实提供了std::string
类型,但这在C ++ string
标头中,而不是C string.h
中.无论如何,它都不会从CCS提供的网站存在中出现C ++编译器,而不是专注于C市场.
C++ does provide a std::string
type but that's in the C++ string
header rather than the C string.h
. In any case, it doesn't appear from their web presence that CCS provides a C++ compiler, instead focusing on the C market.
这篇关于C中有字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!