05-13 07:28
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] Example / Reading a File 본문

Programming/C&C++

[C/C++] Example / Reading a File

cinema4dr12 2014. 6. 12. 10:45

//
//  main.cpp
//
//  Created by gchoi on 2014. 5. 8..
//  Copyright (c) 2014년 gchoi. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <strstream>

const int MAX_SIZE = 256;

using namespace std;

int main(int argc, const char * argv[])
{
    ifstream fin("/Users/gchoi/Documents/Xcode/Test-003/Test-003/test1.txt");
    char c;
    int n;
    float f;
   
    char cc[MAX_SIZE];
   
    fin.getline(cc, MAX_SIZE);
   
    cout << cc << endl;
   
    istrstream is(cc);
    is >> c >> n >> f;
    cout << "char : " << c << endl;
    cout << "int : " << n << endl;
    cout << "float : " << f << endl;
   
    fin.close();
   
    return 0;
}
Comments