grr! i dont understand why its doing this, but for someone it refuses to let the getline statement to work, everytime i compile it says i have the wrong number of arguments, at first it said i had 3 and it needs 2, then i took out the delimeter argument (which according to the msdn thing is supposed to be there) and then i compiled and it said i had 2 and needed 3... wtf?.... i know for a fact i have all the stuff defined correctly cause i even took the example in the msdn thing and it still didnt work correctly... here is is my program and the errors it is giving me, its a lil program thats supposed to be a text based game, nothing complexe, all i need is the stupid thing to get a whole line of input for names and such...
//program:
#include "stdafx.h"
#include "functions.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream.h>
#include <string>
using std::string;
using std::getline;
struct Character
{
public:
string NAME;
int STR, DEX, INT, HITS, STAMINA, MANA;
int LEVEL;
int CURRENTEXP, EXPTOLEVEL;
int WEAPONPOWER, ARMORRATING, MAGICPOWER, MAGICDEFENSE, EVADE, MAGICEVADE;
int EXPGAINED;
string WEAPON, SHIELD, BODYARMOR, LEGARMOR, ARMARMOR, HANDARMOR, NECKARMOR, HEADARMOR;
void save();
void generatestats();
void selectmonster();
void viewstats();
Character::Character();
};
void menu();
void battle();
void equipment();
void buy();
void sell();
void quitwithsave();
void quitwithoutsave();
Character PLAYER;
Character MONSTER;
void main()
{
char bah;
bah=7;
cout << bah << bah << bah; //beep three times
cout << "Battle Arena version .02" << endl;
Skip(2);
int neworload;
cout << "To start a new game press 1 or to load a game press 2." << endl;
cin >> neworload;
//ClearBuffer(); // commented out cause it doesnt work, its something we do at school whenever we have to cin a single int or char, so it skips to the next line... its in the functions.h file
Skip(2);
do
{
if(neworload==1)
{
string charname;
getline(cin,charname);
getline(cin,charname, '\n');
PLAYER.NAME=charname;
PLAYER.generatestats();
menu();
}
else
{
cout << "This option is not available yet.." << endl;
main();
}
}
while( neworload!=1 || neworload!=2 );
}
Character::Character()
{
NAME="unnamed";
STR=0;
DEX=0;
INT=0;
HITS=0;
STAMINA=0;
MANA=0;
LEVEL=1;
}
void Character::generatestats()
{
STR=rand()%25;
DEX=rand()%25;
INT=rand()%25;
while(STR<10)
STR=rand()%25;
while(DEX<10)
DEX=rand()%25;
while(INT<10)
INT=rand()%25;
CURRENTEXP=0;
EXPTOLEVEL=25;
}
void menu()
{
cout << "Select what you wish to do." << endl;
cout << "1. Battle a monster." << endl;
cout << "2. Change equipment." << endl;
cout << "3. Buy equipment." << endl;
cout << "4. Sell equipment." << endl;
cout << "5. View your stats." << endl;
cout << "6. Save your data." << endl;
cout << "7. Save and quit." << endl;
cout << "8. Quit without saving." << endl;
int menuselection;
cin >> menuselection;
//ClearBuffer();
switch(menuselection)
{
case 1 : battle();
break;
case 2 : equipment();
break;
case 3 : buy();
break;
case 4 : sell();
break;
case 5 : PLAYER.viewstats();
break;
case 6 : PLAYER.save();
break;
case 7 : quitwithsave();
break;
case 8 : quitwithoutsave();
break;
default : cout << "That is not a valid choice." << endl;
Skip(2);
menu();
}
}
void battle()
{
MONSTER.selectmonster();
}
void equipment()
{
}
void buy()
{
}
void sell()
{
}
void Character::viewstats()
{
cout << PLAYER.NAME.c_str() << "s Current Stats:" << endl;
cout << "Level: " << PLAYER.LEVEL << endl;
cout << "Strength: " << PLAYER.STR << endl;
cout << "Intelligence: " << PLAYER.INT << endl;
cout << "Dexterity: " << PLAYER.DEX << endl;
Skip(2);
cout << "Weapon Power: " << PLAYER.WEAPONPOWER << endl;
cout << "Armor Rating: " << PLAYER.ARMORRATING << endl;
cout << "Magic Attack: " << PLAYER.MAGICPOWER << endl;
cout << "Magic Defense: " << PLAYER.MAGICDEFENSE << endl;
cout << "Evade: " << PLAYER.EVADE << endl;
cout << "Magic Evade: " << PLAYER.MAGICEVADE << endl;
Skip(2);
cout << "Total Experience: " << PLAYER.CURRENTEXP << endl;
cout << "Experience needed to level up: " << PLAYER.EXPTOLEVEL << endl;
Skip(2);
cout << "Current Equipment:" << endl;
cout << PLAYER.WEAPON.c_str() << endl;
cout << PLAYER.SHIELD.c_str() << endl;
cout << PLAYER.BODYARMOR.c_str() << endl;
cout << PLAYER.LEGARMOR.c_str() << endl;
cout << PLAYER.ARMARMOR.c_str() << endl;
cout << PLAYER.HANDARMOR.c_str() << endl;
cout << PLAYER.NECKARMOR.c_str() << endl;
cout << PLAYER.HEADARMOR.c_str() << endl;
Skip(2);
cout << "To return to the main menu press 1 then enter." << endl;
int returntomenu;
cin >> returntomenu;
menu();
}
void Character::save()
{
//string filename;
//cout << "Enter the name of the file you data in." << endl;
ofstream OutFile;
//OutFile.open(filename.c_str());
OutFile.open("savegame.sav"
OutFile << PLAYER.NAME.c_str() << endl;
OutFile << PLAYER.LEVEL << endl;
OutFile << PLAYER.STR << endl;
OutFile << PLAYER.INT << endl;
OutFile << PLAYER.DEX << endl;
OutFile << PLAYER.WEAPONPOWER << endl;
OutFile << PLAYER.ARMORRATING << endl;
OutFile << PLAYER.MAGICPOWER << endl;
OutFile << PLAYER.MAGICDEFENSE << endl;
OutFile << PLAYER.EVADE << endl;
OutFile << PLAYER.MAGICEVADE << endl;
OutFile << PLAYER.CURRENTEXP << endl;
OutFile << PLAYER.EXPTOLEVEL << endl;
OutFile << PLAYER.WEAPON.c_str() << endl;
OutFile << PLAYER.SHIELD.c_str() << endl;
OutFile << PLAYER.BODYARMOR.c_str() << endl;
OutFile << PLAYER.LEGARMOR.c_str() << endl;
OutFile << PLAYER.ARMARMOR.c_str() << endl;
OutFile << PLAYER.HANDARMOR.c_str() << endl;
OutFile << PLAYER.NECKARMOR.c_str() << endl;
OutFile << PLAYER.HEADARMOR.c_str() << endl;
OutFile.close();
}
void quitwithsave()
{
}
void quitwithoutsave()
{
}
void Character::selectmonster()
{
int select;
if(PLAYER.LEVEL<5)
select=rand()%4;
switch(select)
{
case 0 : MONSTER.NAME="Imp";
MONSTER.STR=5;
MONSTER.HITS=5;
MONSTER.DEX=4;
MONSTER.STAMINA=4;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=4;
MONSTER.WEAPONPOWER=2;
MONSTER.ARMORRATING=3;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=2;
MONSTER.MAGICEVADE=1;
break;
case 1 : MONSTER.NAME="Slime";
MONSTER.STR=2;
MONSTER.HITS=2;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=1;
MONSTER.WEAPONPOWER=1;
MONSTER.ARMORRATING=2;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=0;
MONSTER.EVADE=20;
MONSTER.MAGICEVADE=0;
break;
case 2 : MONSTER.NAME="Headless";
MONSTER.STR=4;
MONSTER.HITS=4;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=5;
MONSTER.WEAPONPOWER=6;
MONSTER.ARMORRATING=4;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=5;
MONSTER.MAGICEVADE=1;
break;
case 3 : MONSTER.NAME="Bandit";
MONSTER.STR=6;
MONSTER.HITS=6;
MONSTER.DEX=8;
MONSTER.STAMINA=8;
MONSTER.INT=3;
MONSTER.MANA=3;
MONSTER.LEVEL=2;
MONSTER.EXPGAINED=6;
MONSTER.WEAPONPOWER=2;
MONSTER.ARMORRATING=3;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=2;
MONSTER.MAGICEVADE=1;
break;
case 4 : MONSTER.NAME="Giant Toad";
MONSTER.STR=7;
MONSTER.HITS=7;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=7;
MONSTER.WEAPONPOWER=4;
MONSTER.ARMORRATING=5;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=0;
MONSTER.EVADE=1;
MONSTER.MAGICEVADE=0;
break;
}
}
//errors:
--------------------Configuration: Battle Arena - Win32 Debug--------------------
Compiling...
Battle Arena.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : expects 2 argume
nts - 3 provided
c:\program files\microsoft visual studio\vc98\include\string(145) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
Error executing cl.exe.
Battle Arena.exe - 4 error(s), 0 warning(s)
//program:
#include "stdafx.h"
#include "functions.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream.h>
#include <string>
using std::string;
using std::getline;
struct Character
{
public:
string NAME;
int STR, DEX, INT, HITS, STAMINA, MANA;
int LEVEL;
int CURRENTEXP, EXPTOLEVEL;
int WEAPONPOWER, ARMORRATING, MAGICPOWER, MAGICDEFENSE, EVADE, MAGICEVADE;
int EXPGAINED;
string WEAPON, SHIELD, BODYARMOR, LEGARMOR, ARMARMOR, HANDARMOR, NECKARMOR, HEADARMOR;
void save();
void generatestats();
void selectmonster();
void viewstats();
Character::Character();
};
void menu();
void battle();
void equipment();
void buy();
void sell();
void quitwithsave();
void quitwithoutsave();
Character PLAYER;
Character MONSTER;
void main()
{
char bah;
bah=7;
cout << bah << bah << bah; //beep three times
cout << "Battle Arena version .02" << endl;
Skip(2);
int neworload;
cout << "To start a new game press 1 or to load a game press 2." << endl;
cin >> neworload;
//ClearBuffer(); // commented out cause it doesnt work, its something we do at school whenever we have to cin a single int or char, so it skips to the next line... its in the functions.h file
Skip(2);
do
{
if(neworload==1)
{
string charname;
getline(cin,charname);
getline(cin,charname, '\n');
PLAYER.NAME=charname;
PLAYER.generatestats();
menu();
}
else
{
cout << "This option is not available yet.." << endl;
main();
}
}
while( neworload!=1 || neworload!=2 );
}
Character::Character()
{
NAME="unnamed";
STR=0;
DEX=0;
INT=0;
HITS=0;
STAMINA=0;
MANA=0;
LEVEL=1;
}
void Character::generatestats()
{
STR=rand()%25;
DEX=rand()%25;
INT=rand()%25;
while(STR<10)
STR=rand()%25;
while(DEX<10)
DEX=rand()%25;
while(INT<10)
INT=rand()%25;
CURRENTEXP=0;
EXPTOLEVEL=25;
}
void menu()
{
cout << "Select what you wish to do." << endl;
cout << "1. Battle a monster." << endl;
cout << "2. Change equipment." << endl;
cout << "3. Buy equipment." << endl;
cout << "4. Sell equipment." << endl;
cout << "5. View your stats." << endl;
cout << "6. Save your data." << endl;
cout << "7. Save and quit." << endl;
cout << "8. Quit without saving." << endl;
int menuselection;
cin >> menuselection;
//ClearBuffer();
switch(menuselection)
{
case 1 : battle();
break;
case 2 : equipment();
break;
case 3 : buy();
break;
case 4 : sell();
break;
case 5 : PLAYER.viewstats();
break;
case 6 : PLAYER.save();
break;
case 7 : quitwithsave();
break;
case 8 : quitwithoutsave();
break;
default : cout << "That is not a valid choice." << endl;
Skip(2);
menu();
}
}
void battle()
{
MONSTER.selectmonster();
}
void equipment()
{
}
void buy()
{
}
void sell()
{
}
void Character::viewstats()
{
cout << PLAYER.NAME.c_str() << "s Current Stats:" << endl;
cout << "Level: " << PLAYER.LEVEL << endl;
cout << "Strength: " << PLAYER.STR << endl;
cout << "Intelligence: " << PLAYER.INT << endl;
cout << "Dexterity: " << PLAYER.DEX << endl;
Skip(2);
cout << "Weapon Power: " << PLAYER.WEAPONPOWER << endl;
cout << "Armor Rating: " << PLAYER.ARMORRATING << endl;
cout << "Magic Attack: " << PLAYER.MAGICPOWER << endl;
cout << "Magic Defense: " << PLAYER.MAGICDEFENSE << endl;
cout << "Evade: " << PLAYER.EVADE << endl;
cout << "Magic Evade: " << PLAYER.MAGICEVADE << endl;
Skip(2);
cout << "Total Experience: " << PLAYER.CURRENTEXP << endl;
cout << "Experience needed to level up: " << PLAYER.EXPTOLEVEL << endl;
Skip(2);
cout << "Current Equipment:" << endl;
cout << PLAYER.WEAPON.c_str() << endl;
cout << PLAYER.SHIELD.c_str() << endl;
cout << PLAYER.BODYARMOR.c_str() << endl;
cout << PLAYER.LEGARMOR.c_str() << endl;
cout << PLAYER.ARMARMOR.c_str() << endl;
cout << PLAYER.HANDARMOR.c_str() << endl;
cout << PLAYER.NECKARMOR.c_str() << endl;
cout << PLAYER.HEADARMOR.c_str() << endl;
Skip(2);
cout << "To return to the main menu press 1 then enter." << endl;
int returntomenu;
cin >> returntomenu;
menu();
}
void Character::save()
{
//string filename;
//cout << "Enter the name of the file you data in." << endl;
ofstream OutFile;
//OutFile.open(filename.c_str());
OutFile.open("savegame.sav"
OutFile << PLAYER.NAME.c_str() << endl;
OutFile << PLAYER.LEVEL << endl;
OutFile << PLAYER.STR << endl;
OutFile << PLAYER.INT << endl;
OutFile << PLAYER.DEX << endl;
OutFile << PLAYER.WEAPONPOWER << endl;
OutFile << PLAYER.ARMORRATING << endl;
OutFile << PLAYER.MAGICPOWER << endl;
OutFile << PLAYER.MAGICDEFENSE << endl;
OutFile << PLAYER.EVADE << endl;
OutFile << PLAYER.MAGICEVADE << endl;
OutFile << PLAYER.CURRENTEXP << endl;
OutFile << PLAYER.EXPTOLEVEL << endl;
OutFile << PLAYER.WEAPON.c_str() << endl;
OutFile << PLAYER.SHIELD.c_str() << endl;
OutFile << PLAYER.BODYARMOR.c_str() << endl;
OutFile << PLAYER.LEGARMOR.c_str() << endl;
OutFile << PLAYER.ARMARMOR.c_str() << endl;
OutFile << PLAYER.HANDARMOR.c_str() << endl;
OutFile << PLAYER.NECKARMOR.c_str() << endl;
OutFile << PLAYER.HEADARMOR.c_str() << endl;
OutFile.close();
}
void quitwithsave()
{
}
void quitwithoutsave()
{
}
void Character::selectmonster()
{
int select;
if(PLAYER.LEVEL<5)
select=rand()%4;
switch(select)
{
case 0 : MONSTER.NAME="Imp";
MONSTER.STR=5;
MONSTER.HITS=5;
MONSTER.DEX=4;
MONSTER.STAMINA=4;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=4;
MONSTER.WEAPONPOWER=2;
MONSTER.ARMORRATING=3;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=2;
MONSTER.MAGICEVADE=1;
break;
case 1 : MONSTER.NAME="Slime";
MONSTER.STR=2;
MONSTER.HITS=2;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=1;
MONSTER.WEAPONPOWER=1;
MONSTER.ARMORRATING=2;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=0;
MONSTER.EVADE=20;
MONSTER.MAGICEVADE=0;
break;
case 2 : MONSTER.NAME="Headless";
MONSTER.STR=4;
MONSTER.HITS=4;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=5;
MONSTER.WEAPONPOWER=6;
MONSTER.ARMORRATING=4;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=5;
MONSTER.MAGICEVADE=1;
break;
case 3 : MONSTER.NAME="Bandit";
MONSTER.STR=6;
MONSTER.HITS=6;
MONSTER.DEX=8;
MONSTER.STAMINA=8;
MONSTER.INT=3;
MONSTER.MANA=3;
MONSTER.LEVEL=2;
MONSTER.EXPGAINED=6;
MONSTER.WEAPONPOWER=2;
MONSTER.ARMORRATING=3;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=1;
MONSTER.EVADE=2;
MONSTER.MAGICEVADE=1;
break;
case 4 : MONSTER.NAME="Giant Toad";
MONSTER.STR=7;
MONSTER.HITS=7;
MONSTER.DEX=3;
MONSTER.STAMINA=3;
MONSTER.INT=1;
MONSTER.MANA=1;
MONSTER.LEVEL=1;
MONSTER.EXPGAINED=7;
MONSTER.WEAPONPOWER=4;
MONSTER.ARMORRATING=5;
MONSTER.MAGICPOWER=0;
MONSTER.MAGICDEFENSE=0;
MONSTER.EVADE=1;
MONSTER.MAGICEVADE=0;
break;
}
}
//errors:
--------------------Configuration: Battle Arena - Win32 Debug--------------------
Compiling...
Battle Arena.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : expects 2 argume
nts - 3 provided
c:\program files\microsoft visual studio\vc98\include\string(145) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
C:\Program Files\Microsoft Visual Studio\MyProjects\Battle Arena\Battle Arena.cpp(56) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could n
ot deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class istream_withassign'
Error executing cl.exe.
Battle Arena.exe - 4 error(s), 0 warning(s)