PDcurses从文件

时间:2017-06-12 13:00:49

标签: c++ string visual-studio pdcurses

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

的main.cpp

#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
}

0 个答案:

没有答案