#include <string>
#include <iostream>
using namespace std; void main()
{
string str1="MMM" ,str2="VVVV";
sprintf( str1, "%2.2s%s", str2, str1 );
cout < <str1 < <endl;
} 在VC6中我选择的是控制台程序类型,编译上面代码时出错
各位大哥哪里错了啊
#include <iostream>
using namespace std; void main()
{
string str1="MMM" ,str2="VVVV";
sprintf( str1, "%2.2s%s", str2, str1 );
cout < <str1 < <endl;
} 在VC6中我选择的是控制台程序类型,编译上面代码时出错
各位大哥哪里错了啊
#include <string>
#include <iostream> using namespace std;int main(int argc, char* argv[])
{
string str1="MMM",str2="VVVV";
char buff[256];
sprintf( buff, "%2.2s%s", str2.c_str(), str1.c_str() );
cout << buff <<endl; return 0;
}
sprintf的参数是char类型,不是string类型哈