// teststrcat.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <windows.h> #include <string> using namespace std; int main(int argc, char* argv[]) { char strBuffert[256] ={0}; DWORD dwSize2 = 256; GetUserName(strBuffert,&dwSize2); char winexe11[256] = "C:\Users\"; char winexe22[256] = "\AppData\Roaming\tian\tian.exe"; char winexe77[256] = "\AppData\Local\Temp\zzzz.exe"; char* winexe44 = strcat(winexe11,strBuffert); char* winexe55 = strcat(winexe44,winexe22); char* winexe88 = strcat(winexe11,strBuffert); char* winexe99 = strcat(winexe88,winexe77); cout<<winexe44<<"==="<<winexe99<<endl; return 0; } 为什么运行结果winexe44得到的是C:\Users\Jevon\AppData\Roaming\tian\tian.exeJevon\AppData\Local\Temp\zzzz.exe,而不是C:\Users\Jevon\AppData\Roaming\tian\tian.exe. |
|
char *strcat(char *dest, const char *src);
RETURN VALUE |
|
winexe44 winexe99 都指向 winexe11 必然结果相同
|
|
20分 |
winexe44 winexe99 都指向 winexe11 必然结果相同
|
20分 |
楼上正解!winexe44指向的是winexe11的地址,没执行一句都在后面加了内容
你逐行输出一下: char* winexe44 = strcat(winexe11,strBuffert); cout << winexe44 << endl; char* winexe55 = strcat(winexe44,winexe22); cout << winexe44 << endl; char* winexe88 = strcat(winexe11,strBuffert); cout << winexe44 << endl; |
谢谢各位了,之前学的是C#,感觉两者在连接字符串区别很大,现在还是理解不了,自己再慢慢学,不懂的再来问各位,谢谢了!
|