知道了C++的I/O设施之后。这些就变的非常easy了。
假设你常常使用,时间长了就会有感觉。这个事情是多此一举吗?就当是练习吧,知道原理之后,你会认为用起来更舒畅,更喜欢C++了。
#include <iostream> #include <vector> #include <string> #include <sstream> #include <algorithm> #include <iterator> using namespace std; template<typename Result,typename Para> Result lexical_cast(Para para) { stringstream ss; ss<<para; Result result; ss>>result; return result; } //int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) int main(int argc, char *argv[]) { double arr[10] = {0.1,1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.0}; vector<string> str_arr; for (size_t i =0 ; i< sizeof(arr)/sizeof(double) ; ++i) { str_arr.push_back(lexical_cast<string>(arr[i])); } ostream_iterator<string> out(cout," "); copy(str_arr.begin(),str_arr.end(),out); return 0; }
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2FsbXJlYXNvbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >
时间: 2024-11-06 02:47:16