Linux c++ 转string模板函数,写文件

#include <iostream>
#include <sstream>

using namespace std;
//转string模板函数 template
<class T> string toString(const T &v) { ostringstream os; os << v; return os.str(); } int main() { int a = 4; float aa = 4.01; double dd = 33.566; string straa = toString(a); string straaa = toString(aa); string straab = toString(dd); cout << straa << endl; cout << straaa << endl; cout << straab << endl; return 0; }

 

  

int writeFile(string charFpName, string chVal) //写文件
{	
	FILE *fp = fopen(charFpName.c_str(),"w+");
	if(NULL == fp){		
		return 0;
	}	
	fprintf(fp,"%s\n",chVal.c_str());
	fclose(fp);
	return 1;	
}

  

posted @ 2019-04-14 10:26  茫茫明明  阅读(928)  评论(0编辑  收藏  举报