0

我在使用 PDcurses 打印字符串时遇到问题。编译器没有显示错误,但是当我打开程序时它立即停止工作。当我使用 cout 打印它时,它可以正常工作。

主文件

#include "Item.h"
#include "Character.h"
#include "Inventory.h"
#include<iostream>
#include <curses.h>

using namespace std;

int col = 0;
int row = 0;

int main() {
    Character player("Roland", 1, 500, 200, "Knight");
    char* playerChar = (char*)alloca(player.drawCharacter().size() +1);
    memcpy(playerChar, player.drawCharacter().c_str(), player.drawCharacter().size() + 1);
    //cout << playerChar;

    //playerChar = "dasdasdasdsadasdsadsad";

    initscr();
    getmaxyx(stdscr, row, col);
    mvprintw(6,6,playerChar);
    getch();
    endwin();

    return 0;
}

我的功能

string Character::drawCharacter() {
    ifstream file ("Character/Knight_axe.txt");             //Open file

    string lines = "";                                  //Store all lines

    if (file){                                          //Check if everything is good
        while (file.good ()){
        string TempLine;                                //Temp line
        getline (file , TempLine);                      //Get temp line
        TempLine += "\n";                               //Add newline character

        lines += TempLine;                              //Add newline
        }
    } else {
        lines = "ERROR File does not exist.";           //Return error
    }

    file.close ();                                      //Close file
    return lines;                                       //Print it to the screen
}
4

0 回答 0