Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
775 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...