分別採用C語言和C++輸出資料到txt文本

來源:互聯網
上載者:User
C語言的實現

#include <stdio.h>

FILE *fpo;                        
FILE *fpt; 

int main( int argc, char** argv )
{
    fpo=fopen("po.txt", "w+");     
    fpt=fopen("pt.txt", "w+");     

    fprintf(fpo, "%d\t%d\n", pt1.x, pt1.y );  
    fprintf(fpt, "%d\t%d\n", pt2.x, pt2.y );     // 注意如果整型資料採用浮點形式輸出時,結果為0 

    fclose(fpo);
    fclose(fpt);

   

    printf("\n同時ALT鍵和滑鼠右鍵按下將縮小匹配結果圖\n\n"); // 輸出資料到顯示終端
    fprintf( stderr, "Finding features in %s...\n", img2_file );

}

/////////////////////////////////////

C++語言的實現

#include <iostream>
#include <fstream>
using namespace std;

int main( int argc, char** argv )
{
   ofstream poi1,poi2;
   poi1.open("point_O.txt",ios::out|ios::app);
   poi1.setf(ios::fixed, ios::floatfield);
   poi1.setf(ios::showpoint);

   poi2.open("point_T.txt",ios::out|ios::app);
   poi2.setf(ios::fixed, ios::floatfield);
   poi2.setf(ios::showpoint);

   poi1<< matches[i].first.x  << "\t" << matches[i].first.y  << endl;
   poi2<< matches[i].second.x << "\t" << matches[i].second.y << endl;

   poi1.close();
   poi2.close();

   std::cout<< "Matches: " << matches.size(); // 輸出資料到顯示終端

}

 

// 注意如果在尾碼為C的源檔案上,採用C++輸出方法來輸出資料到txt檔案,VS2008編譯器可能報錯。解決方案是將尾碼改為CPP,並另建一個新的工程,然後採用c++的輸出方法,這樣比較方便些。如果C檔案中使用了一些非法關鍵字,那麼修改這些變數的定義,以免與c++的關鍵字重複定義。

http://blog.sina.com.cn/s/blog_702eac8701013k5m.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.