파일에서 문자 하나씩 읽기 C FILE* fp; fp = fopen("HelloWorld.txt", "r"); char character; do { character = getc(fp); printf("%c", character); } while (character != EOF); fclose(fp); C++ ifstream fin; fin.open("HelloWorld.txt"); char character; while (true) { fin.get(character); if (fin.fail()) { break; } cout > 어떤 스트림(예: cin, istreingstream)을 넣어도 동일하게 동작 fin.get(character); fin.getline(firstName, 20);// 파일에..
C FILE *fp; // 읽기 전용으로 파일을 오픈 fp = fopen("helloWorld.txt", "r"); // 쓰기 전용으로 파일을 오픈 (파일이 없으면 만듦) fp = fopen("helloWorld.txt", "w+"); // 읽기와 쓰기 범용으로 파일을 오픈 fp = fopen("helloWorld.txt", "r+"); C++ // 읽기 전용으로 파일을 오픈 ifstream fin; fin.open("helloWorld.txt"); // 쓰기 전용으로 파일을 오픈 (파일이 없으면 만듦) ofstream fout; fout.open("helloWorld.txt"); // 읽기와 쓰기 범용으로 파일을 오픈 fstream fs; fs.open("helloWorld.txt"); open() f..

#include int main() { char data[2] = ""; scanf("%s", data); printf("%s\n", data); return 0; } 에러 메세지를 보면 scanf 대신 scanf_s로 사용하라고 하는데 그 이유는 scanf가 구조적으로 안정적이지 않아 여러 위험을 안고 있는 함수이기 때문이다. 그러한 문제점을 보완하여 나온 것이 scanf_s 이다. VS2010 이상 컴파일러에서는 scanf_s 함수를 사용하도록 권장하고 있다. 그렇다면 scanf_s 는 어떤 점이 달라진 것일까. 기존 scanf 는 char 형이나 문자열을 넣을 때 받을 수 있는 문자열의 사이즈를 넣지 않아도 사용이 가능했었다. 그로인한 문제점이 바로 오버플로우(overflow)이다. #pragma ..
.h 를 안붙여도 되고 앞에 c를 붙이면된다. C C++