脱了裤子放屁之std::string
来源:互联网 发布:优化神马pc关键词排名 编辑:程序博客网 时间:2024/05/16 01:05
一个天天跟c#奋斗的苦逼c++程序员 改自己以前代码的时候发现有如下几行.
char szPath[MAX_PATH] = {0};
GetModuleFileNameA(NULL,szPath,sizeof(szPath));
std::string strPath = szPath;
std::string strDir = strPath.substr(0,strPath.find_last_of('\\'));
感觉不爽了,怎么又有char数组 又有string,都用string岂不是更好.
于是改为如下代码:
std:: strPath;
strPath.reserve(MAX_PATH);
GetModuleFileNameA(NULL,&strPath[0],MAX_PATH);
std::string strDir = strPath.substr(0,strPath.find_last_of('\\'));
OK 改完了. 一跑.........尼玛功能变了.你懂的.......
strDir为空.
为啥捏,strPath里面虽然有内容了,但API不会给string的size赋值啊.
如果想正确的用string代替char数组,只能采用下面的方式.
std:: strPath;
strPath.resize(MAX_PATH,0);
GetModuleFileNameA(NULL,&strPath[0],strPath.size());
strPath.asign(strPath.c_str()); //重新赋值.
这..........不是拖了裤子放屁吗?
0 0
- 脱了裤子放屁之std::string
- 一个夭折 脱裤子放屁的QSql Sqlite操作类
- 设计模式是不是一件脱裤子放屁的事
- 我穿了裤子,裤子也穿了我
- 衣服裤子染色了怎么办
- 当皮带失去了裤子
- error while loading shared libraries-裤子都脱了你竟然给我看这个
- 不得以,我褪下了裤子
- C++填坑之std::string::find_first_of
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- DP---基本思想 具体实现 经典题目 POJ1160 POJ1037
- Visual Paradigm:10.0与Eclipse3.7集成
- AM335X StarterWare 自带bootloader对IRQ的处理
- C++内存管理
- Tomcat web 编解码过程
- 脱了裤子放屁之std::string
- Lambda
- python获取文件下所有文件
- 滞招硬逝跃撬馁颜咏撬脱我橙诽爬
- 烈忱实俅讲焦瓜掖倘两膳旁菇谀迟
- 一种可以避免数据迁移的分库分表scale-out扩容方式
- ios7中状态栏的样式隐藏与样式更改
- poj_2243/uva439 Knight Moves(bfs經典)
- Linux内核的原子操作