Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 views
in Technique[技术] by (71.8m points)

c++ - Is there string in C?

Is there string in CCS?

Can I use:

string myString = "My String"; // Error

or NOT?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
", 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...