C中有字符串吗? [英] Is there string in C?

查看:133
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆