文字列オブジェクトをcoutする単純なプログラムを実行しようとすると、実行時にクラッシュします。次のコードでBorlandC++コンパイラバージョン5.5を使用しています。
#include <iostream>
#include <string> // Usaremos as funcoes mais modernas de String em C++
#include <conio.h>
using namespace std;
// <Prototipos >
int MenuPrincipal(void);
void DesenharCentralizado(string String, int CoordY);
// </Prototipos>
int main() {
while(MenuPrincipal() != 0); // Para sair, ele deve retornar 0
return 0;
}
int MenuPrincipal(void) {
string Titulo = "Agenda";
clrscr();
DesenharCentralizado(Titulo, 4);
getch();
return 0;
}
void DesenharCentralizado(string Frase, int CoordY) {
int PosX=wherex(), PosY=wherey();
gotoxy((80-Frase.length())/2, CoordY);
cout << Frase; // XXX CRASH
gotoxy(PosX, PosY);
}
PS:古いconio.hの使用について文句を言わないでください。これらは、私のC ++クラス用であり、先生が最初に使用するように教えてくれています…