2016-05-19 6 views
-2

オーバーロードされた関数を使用して構造体のファイルを印刷するにはどうすればよいですか?オーバーロードされた関数を使用してファイルを表示

私は、シンボルと配列を出力し、構造体であるファイルを出力する必要がある、過充電関数SHOWを持っています。

#include <iostream> 
#include <conio.h> 

using namespace std; 

void show(char c) 
{ 
    cout << "\n Symbol: " << c << endl; 
} 

void show(int* m, int n) 
{ 
    cout << "\n Array: "; 
    for (int i = 0; i < n; i++) 
    { 
     cout << m[i] << ((i == n-1) ? "" : ", "); 
    } 
    cout << endl; 
} 

int main() 
{ 
    int m[10] = {16, 78, 99, 6, -29, 19, -52, 65, -88, 51}; 
    show(m, 10); 
    show('a'); 

    _getch(); 
} 
+2

_overcharged function_ – Tas

+0

あなたは '新しい過負荷'無効ショー(ファイル*のMY_FILE)を提供する必要があります。何を試しましたか? – GeorgeAl

+0

@GeorgeAlとそれが主な機能にどのようにあるでしょうか? – Neon

答えて

0

あなたはSTDを使用してファイルを読み込むことができます::はifstream(#include <fstream>)と、コンソールにそれをストリーム:

void show(std::string filepath) 
{ 
    //file reader 
    std::ifstream file(filepath); 
    std::string strline; 
    // while you're not at the end of the file, read the current line 
    while(getline(file, strline)) 
     //display the line in console 
     std::cout << strline<< std::endl; 
} 
関連する問題