벡터를 사용하려고하는 최고 점수 목록에 최신 최신 업데이트를 표시하도록 코드를 업데이트하기 만하면됩니다. 나는 벡터 진술을 꺼 냈지만, 여기이 사실을 알고, 텍스트 파일에서 글쓰기와 읽기에 완벽하게 작동한다. 주의 -이 코드를 한 사람 만 업데이트하면 새로운 코드를 볼 수 있습니다.C++에서 벡터를 사용하는 최고 점수 목록
// Get the scores from the game
int getHighscore()
{
ShowConsoleCursor(true);
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
fstream file;
file.open("Highscores.txt", ios::out | ios::app);
if(file.good()==true) {
string TextLimit;
TextLimit = charLimit();
file << TextLimit;
for(int a=0; a<=40-TextLimit.length(); a++) {
file<<" ";
}
file<<Killed<<endl;
file.close();
}
ShowConsoleCursor(false);
return 0;
}
// Displays the scores from the game
void HighscoreResults()
{
system("cls");
fstream file;
file.open("Highscores.txt", ios::in);
if(file.good()==true)
{
string p1Name;
SetColor(11);
CPos(1,15); cout << " _ _ _ _ \n";
CPos(2,15); cout << " | | | (_) __ _| |__ ___ ___ ___ _ __ ___ ___ \n";
CPos(3,15); cout << " | |_| | |/ _` | '_ \\/ __|/ __/ _ \\| '__/ _ \\/ __| \n";
CPos(4,15); cout << " | _ | | (_| | | | \\__ \\ (_| (_) | | | __/\\__ \\ \n";
CPos(5,15); cout << " |_| |_|_|\\__, |_| |_|___/\\___\\___/|_| \\___||___/ \n";
CPos(6,15); cout << " |___/ \n";
CPos(7,10); SetColor(10);
cout << " ------------------------------------------------------------";
CPos(9,15); SetColor(14);
cout << " Names:\n";
CPos(9,50);
cout << " Zombies Killed:\n"; SetColor(15);
while(getline(file, p1Name))
{
cout << " " << p1Name << endl;
}
file.close();
}
else
{
cout<<"The file cannot open!";
system("pause >nul");
}
}
// Makes where only a 8 char can be entered when entering a name
string charLimit()
{
int characters=-1;
char text[10];
int Button;
string TextLimit;
while(true)
{
// Clears the name when backspaced
CPos(20, 13);
cout<<" ";
CPos(20, 13);
cout<<" Name: ";
// Puts a limit on the characters of the text
for(int a=0; a<=characters; a++)
{
cout<<text[a];
}
Button = getch();
if(Button==13 && characters>0)
{
for(int a=0; a<=characters; a++)
{
if(text[a]!=' ') TextLimit = TextLimit + text[a];
}
return TextLimit;
}
if(Button==8 && characters>=0)
{
text[characters] = ' ';
characters--;
}
else if(Button!=8 && characters+1<=9)
{
characters++;
text[characters] = Button;
}
}
}
출력이란 무엇입니까? 벡터는 어디에서 정렬됩니까? 벡터 안에는 단 하나의 아이템이있는 것처럼 보입니다. –
@qamyoncu 공백의 출력 HighscoreResults(); 그리고 벡터와 함께, 나는 그들에게 아직 익숙하지 않고 텍스트 문서 안에서 하나를 사용하는 방법에 대해 매우 혼란 스럽다. – ProgrammerRyan98
@ ProgrammerRyan98 살해의 유형은 무엇입니까? – furkle