Is there string in C?

余生长醉 提交于 2020-01-07 09:53:52

问题


Is there string in CCS?

Can I use:

string myString = "My String"; // Error

or NOT?


回答1:


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;
}

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++ 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.



来源:https://stackoverflow.com/questions/59559083/is-there-string-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!