c++ 공부 조금

2022. 9. 18. 22:39카테고리 없음

//1. 옵션을 보여줘 - 그리고 저장해줘
//몇개의 선택을 받을 것인가 
#include <iostream>

void showOption(){
	int choice;
	string filePath = "test,txt";

	while(choice!=7){
		cout<<"================================="<<endl;
		cout<<"select options"<<endl;
		cout<<"1. 1번 option"<<endl;
		cout<<"2. 2번 option"<<endl;
		cout<<"3. 3번 option"<<endl;
		cout<<"4. 4번 option"<<endl;
		cout<<"5. 5번 option"<<endl;
		cout<<"6. 6번 option"<<endl;
		cout<<"7. 7번 option"<<endl;
		cin>>choice;
		outFile << choice << endl;
	}
	outFile.close();
	
}

//2. 받은 파일을 열어서 읽어
void openFile(){
	ofstream outFile;

	ifstream inFile;

	inFile.open("numbers.txt");
	if (inFile.is_open() == false) {
		cout << "Unable to openthe file" << endl;
		return -1;
	}
	int value;
	int sum(0);

	while (true) {
		//아직도 읽을 내용이 있는가 확인
		if (inFile.good() == false) {
			break;
		}
		inFile >> value;
		give(value);
	}

	//end of file, 파일 끝에 도달하면 true
	if (inFile.eof() == true) {
		cout << "Sum is " << sum << endl;
		inFile.close();
		return 0;
	}

	//파일이 끝이 아닌데 읽기 실패
	else if (inFile.fail() == true) {
		cout << "Failure,, file read" << endl;
		inFile.close();
		return -1;
	}
	inFile.close();

//출처: https://0-sunny.tistory.com/32 [웅웅 영넌이 말이 다 맞아요!!:티스토리]
}


//3. 해당하는 것의 원하는 것을 주자 
void give(int num){
	swich(num){
		case 1:
		//내용 적어 
		break;

		case 2:
		//내용 적어 
		break;
		
		case 3:
		//내용 적어 
		break;
		
		case 4:
		//내용 적어 
		break;
	}
}


//2. 옵션을 저장해줘
#include <fstream>

void saveFile(){
	string filePath = "test.txt";
	int choice = showOption();
	ofstream outFile; 

	//write file
	outFile.open(filePath);

}