自从接触到KUKA机器人以来,更多关注到了PC层面上的编程。工业现场多是采用快速更换的PLC系统硬件,这些将会注重在现场离散信号控制方面;而PC层面的编程更多会注重在数据传输、显示、存储方面的运用。那么,有什么编程技术值得储备呢?
机器人工程师的非机器人编程技能
Reply
自从接触到KUKA机器人以来,更多关注到了PC层面上的编程。工业现场多是采用快速更换的PLC系统硬件,这些将会注重在现场离散信号控制方面;而PC层面的编程更多会注重在数据传输、显示、存储方面的运用。那么,有什么编程技术值得储备呢?
MFC里面直接使用CString比较方便,不过并不能直接由cout输出。看下面代码,在VC6和VC2010中输出是不同的。
#include <afx.h> #include <iostream> using namespace std; void main() { CString s1="1234567890"; cout<<s1; }
将
cout<<s1;
改为
cout<<s1.GetBuffer(0); //MFC4.2中的,高版本增加GetString()
或者
cout<<LPCTSTR(s1);
就可以输出正确的字符串内容,原理是获取字符串的首地址指针。
由此可以引申出cstring类型转化为string类型方法:
#include <afx.h> #include <iostream> #include <STRING> using namespace std; void main() { string s0="0987654321",s3="",s4=""; CString s1="1234567890"; s1=s0.c_str(); //string类型转换为cstring类型 s3=LPCTSTR(s1); // 注 * s4=s1.GetBuffer(0); //cstring类型转换为string类型 cout<<s0<<endl; cout<<LPCTSTR(s1)<<endl; cout<<s3<<endl; cout<<s4<<endl; }
You can freely substitute CString objects for const char* and LPCTSTR function arguments
LPCTSTR A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.
LPTSTR A 32-bit pointer to a character string that is portable for Unicode and DBCS.
关键字:cstring, string, cout, 指针, LPCTSTR
最近,LT 在用 VC6 开发一个小软件,其中有一个功能是需要由一个 CString 对象含有的十六进制形式的字符串( WinHex 中称之 Hex ASCII : hexadecimal representation of raw data as ASCII text )生成磁盘文件。记录下实现过程以备忘。