|
题目在这里:https://www.cctry.com/thread-289275-1-1.html
- #include <iostream>
- using namespace std;
- int main()
- {
- char world[59] = "hello, friends, my name is cctry.com. what is your name ?\0";
- char world1[] = " I am LiHua";
- int a = strlen(world);
- int b = strlen(world1);
- cout << "a=" << a << endl << "b=" << b <<endl;
- char worldcat[500];
- for (int i = 1; i <=a; ++i)
- {
- worldcat[i] = world[i];
- }
- for (int j = 1; j <= b; ++j)
- {
- worldcat[59+j] = world1[j];
- }
- cout << worldcat << endl;
- }
复制代码
这个是代码,不知道第二段该怎么改,输出的只有world[59]的部分;而且第一个字符是乱码
如果按照楼主的思路来做的话,应该改成这样就可以了:
- #include <iostream>
- using namespace std;
- int main()
- {
- char world[59] = "hello, friends, my name is cctry.com. what is your name ?\0";
- char world1[] = " I am LiHua";
- int a = strlen(world);
- int b = strlen(world1);
- cout << "a=" << a << endl << "b=" << b << endl;
- char worldcat[500] = {0};
- int idx = 0;
- for (int i = 0; i < a; ++i)
- {
- worldcat[idx++] = world[i];
- }
- for (int j = 0; j < b; ++j)
- {
- worldcat[idx++] = world1[j];
- }
- cout << worldcat << endl;
- }
复制代码
|
上一篇: 完成端口 SO_RECEIVE 内存增高的问题。下一篇: 如何把VS2008转换成VS2013,我直接用VS2013,结果在一大堆问题。
|