c++ basic thoughts: char array
来源:互联网 发布:人工智能龙头股票 编辑:程序博客网 时间:2024/06/05 05:24
//strtype3.cpp .. more string class features
#include <iostream>
#include <string>
#include <cstring> // C-styple string library
int main()
{
using namespace std;
char charr1[20];
char charr2[20] = "jaguar";
string str1;
string str2 = "panther";
// assignment for string objects and character arrays
str1 = str2;
strcpy(charr1,charr2);
//appending for string objects and character arrays
str1 += " paste";
strcat(charr1, " juice");
// finding the length of a string object and a C-style string
int len1 = str1.size(); // obtain length of str1
int len2 = strlen(charr1); // obtain length of charr1
cout << "The string " << str1 << " contains " << len1 << " characters.\n";
cout << "The string " << charr1 << " contains " << len2 << " characters.\n";
char site[6]={};
cout << strcat(site, " of pancakes") << endl;;
return 0;
#include <iostream>
#include <string>
#include <cstring> // C-styple string library
int main()
{
using namespace std;
char charr1[20];
char charr2[20] = "jaguar";
string str1;
string str2 = "panther";
// assignment for string objects and character arrays
str1 = str2;
strcpy(charr1,charr2);
//appending for string objects and character arrays
str1 += " paste";
strcat(charr1, " juice");
// finding the length of a string object and a C-style string
int len1 = str1.size(); // obtain length of str1
int len2 = strlen(charr1); // obtain length of charr1
cout << "The string " << str1 << " contains " << len1 << " characters.\n";
cout << "The string " << charr1 << " contains " << len2 << " characters.\n";
char site[6]={};
cout << strcat(site, " of pancakes") << endl;;
return 0;
}
Question & answer:
The definition of char site[6] means 'site' gets a address (definitly saying I don't know why?maybe i can answer it on some day) if you use the expresson: "char site[];" replace the "char site[6] = {};" what do you got? A strange symboll in your monitor. the further more we know we should make sure that 'site[6]' need get the guaranteed value, the initial value.different compiler maybe have different behavior.
- c++ basic thoughts: char array
- Thoughts
- thoughts
- Thoughts on TypeScript by Nicholas C. Zakas
- char array string
- typedef char array[10]
- null-terminated char array
- <C>char/char*/char**数组
- C Char* Char[] sizeof
- C++:char* 和 char[]
- c/c++ char*、char[]
- Conversion of C++/CLI array of strings to native C++ char**
- char array和cell arrary
- 041.Char Array 字符数组
- 041.Char Array 字符数组
- array used and char`s array and string`s array
- array.c
- c++:array
- 用size命令分析linux程序内存段的分布
- java平台 javaee javase javame
- [PHP]写SQL语句
- php Mongodb find注意事项
- UVa 10061 How many zero's and how many digits ? (任意进制下的阶乘长度和尾0的数目)
- c++ basic thoughts: char array
- [PHP]中文乱码问题集
- REDHAT下载网站
- hdu 1723 Distribute Message
- NYOJ 2 括号配对问题
- 【总结】android程序不显示图标,开机自动启动?我来告诉你
- 十度好友问题
- Service基础知识点
- 111111