Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您能帮我解释一下为什么这段代码没有按预期打印 '*' 字符的 char 数组吗?
int n = 10; char *cs = (char*) calloc(n + 1, sizeof(char)); for (int i = 0; i < n; i++) { cs[i] = '*'; } cout << cs << endl;
谷歌搜索了很多,但在任何地方都没有发现同样的问题..
谢谢!
我在工作室中编写了相同的代码,对我来说它工作正常。给予*作为输出。
*
int main() { int n=10; char *cs = (char*) calloc(n+1, sizeof(char)); for (int i=0; i<n; i++) { cs[i] = '*'; } cout << cs << endl; return 0; }