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;	
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM