.txt 파일에서 나중에 사용할 수 있도록 일부 데이터를 저장하려고합니다. 코드를 처음 실행할 때 문제가 없습니다. 두 번째로, 모든 지옥은 느슨해집니다. 당신이 파일에 쓸 수있는 함수 I는 다음과 같습니다 :두 번째로 컴파일하지 못했습니다. C++을 실행합니다.
void VideoSelection::write(char Name[255], char address[255])
{
int i = 0;
string iString;
saveFile.open("Movies.txt");
for (string line; getline(input, line);) // check for the number of movies (0-index)
{
iString = to_string(i);
if (line == iString)
{
i++;
}
}
saveFile << i << endl;
saveFile << "NAME: " << Name << " " << "ADDRESS: " << address << endl << endl;
saveFile.close();
}
을 사용 된 헤더 파일은 다음과 같습니다 :
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include "Movies.txt";
using namespace std;
class VideoSelection
{
public:
VideoSelection();
void write(char Name[255], char address[255]);
void read();
void sort();
void open();
~VideoSelection();
protected:
char http[255];
ofstream saveFile;
ifstream input;
};
을 주 :
#include "VideoSelection.h"
int main()
{
VideoSelection VS;
char movieName[255];
char movieAddress[255];
cin >> movieName;
cin >> movieAddress;
VS.write(movieName, movieAddress);
}
이가 있습니다 오류가 발생했습니다.
https://gyazo.com/f5f13e7dfd18378152df6126b7a40be1
설명 : ** # include "Movies.txt"; ** –
#include "Movies.txt"를 제거하십시오. –