#include
#include
#include
using namespace std;
struct Test
{
string a;
string b;
};
int main()
{
Test ta{“123”,“abc”};
cout << ta.a << " " << ta.b << endl;
memset(&ta, 0, sizeof(ta));
ta.a = “7777”;
ta.b = “9999”;
cout << ta.a << " " << ta.b << endl;
string str = “%s is %s %s”;
char s[10];
sprintf(s, str.c_str(), “abc”, “123”, “456456789”);
cout << s << endl;
system(“pause”);
return 0;
}
memset初始化结构体之后,再结构体赋值可能出现问题(linux和windows表现不一样)。
sprintf在格式化数据的时候要注意数据的长度
memset和sprintf小记
最新推荐文章于 2021-05-22 04:41:04 发布