《C++ Primer 中文版》211頁習題7.15 “編寫一個主函數main,使用兩個值作為實參,并輸出它們的和

来源:互联网 发布:jsp项目实例源码下载 编辑:程序博客网 时间:2024/05/16 10:04

感謝原作者的分享:

http://blog.csdn.net/kasher/article/details/6452926



#include <iostream>using std::cout;using std::endl;//211頁習題7.15 “編寫一個主函數main,使用兩個值作為實參,并輸出它們的和int main(int argc,char **argv) { if(argc!=3){cout<<"请使用3个参数!"<<endl;return -1;}cout<<"它们的和是:"<<atof(argv[1])+atof(argv[2])<<endl;return 0;}

atof將字符串轉換成double類型

double atof(   const char *str );double _wtof(   const wchar_t *str );