I have been trying to create a card database keeping program using c++ but when i try to compile the cord I have written I end up getting a temple argument deduction/substitution failed error. Can someone please tell me what is wrong in my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
void cardSearch();
void cardEntry();
int main()
{
int mainSelect;
cout << "Welcome to the Database";
cout << "1: New Card" << endl;
cout << "2: Search Cards" << endl;
cout << "3: Exit Program" << endl;
cin >> mainSelect;
switch (mainSelect)
{
case 1:
cardEntry();
break;
case 2:
cardSearch();
break;
case 3:
return 0;
break;
}
cin.ignore();
cin.clear();
cin.get();
return 0;
}
void cardSearch()
{
string cardName;
string typeOfCard;
string cardAttribute;
int cardLevel;
string cardType;
string cardSubType;
int cardATK;
int cardDEF;
int numberOf;
ofstream monstercardFile("monsters.txt");
ofstream spellcardFile("spells.txt");
ofstream trapcardFile("traps.txt");
int searchChoice;
string searchTerm;
cout << "Which kind of card would you like to search for:" << endl;
cout << "1: Monster" << endl;
cout << "2: Spell" << endl;
cout << "3: Trap" << endl;
cin >> searchChoice;
switch (searchChoice)
{
case 1:
cout << "Search: ";
cin >> searchTerm;
while (monstercardFile >> cardName >> typeOfCard >> cardAttribute >> cardLevel >> cardType >> cardSubType >> cardATK >> cardDEF >> numberOf)
{
if (searchTerm.c_str() == cardName)
{
cout << "Name: " << cardName << endl;
cout << "Type of Card: " << typeOfCard << endl;
cout << "Attribute: " << cardAttribute << endl;
cout << "Level: " << cardLevel << endl;
cout << "Type: " << cardType << endl;
cout << "Sub-Type: " << cardSubType << endl;
cout << "ATK: " << cardATK << endl;
cout << "DEF: " << cardDEF << endl;
cout << "Number Owned: " << numberOf << endl;
cin.ignore();
cin.clear();
cin.get();
}
}
break;
case 2:
cout << "Search: ";
cin >> searchTerm;
while (spellcardFile >> cardName >> typeOfCard >> numberOf)
{
if (searchTerm.c_str() == cardName)
{
cout << "Name: " << cardName << endl;
cout << "Type of Card: " << typeOfCard << endl;
cout << "Number Owned: " << numberOf << endl;
cin.ignore();
cin.clear();
cin.get();
}
}
break;
case 3:
cout << "Search: ";
cin >> searchTerm;
while (trapcardFile >> cardName >> typeOfCard >> numberOf)
{
if (searchTerm.c_str() == cardName)
{
cout << "Name: " << cardName << endl;
cout << "Type of Card: " << typeOfCard << endl;
cout << "Number Owned: " << numberOf << endl;
cin.ignore();
cin.clear();
cin.get();
}
}
break;
}
monstercardFile.close();
spellcardFile.close();
trapcardFile.close();
cardSearch();
}
void cardEntry()
{
string cardName;
string typeOfCard;
string cardAttribute;
int cardLevel;
string cardType;
string cardSubType;
int cardATK;
int cardDEF;
int numberOf;
ofstream monsterFile ("monsters.txt", ios::app);
ofstream spellFile("spells.txt", ios::app);
ofstream trapFile("traps.txt", ios::app);
int selectionEntry;
cout << "1: Monster" << endl;
cout << "2: Spell" << endl;
cout << "3: Trap" << endl;
cout << "Selection: ";
cin >> selectionEntry;
if (selectionEntry == 1)
{
ofstream monsterFile ("monsters.txt", ios::app);
}
else if (selectionEntry == 2)
{
ofstream spellFile("spells.txt", ios::app);
}
else if (selectionEntry == 3)
{
ofstream trapFile("traps.txt", ios::app);
}
switch (selectionEntry)
{
case 1:
cout << "Name: ";
cin >> cardName;
cout << "Type of Card: ";
cin >> typeOfCard;
cout << "Attribute: ";
cin >> cardAttribute;
cout << "Level: ";
cin >> cardLevel;
cout << "Type: ";
cin >> cardType;
cout << "Sub-Type: ";
cin >> cardSubType;
cout << "ATK: ";
cin >> cardATK;
cout << "DEF: ";
cin >> cardDEF;
cout << "Number Owned: ";
cin >> numberOf;
monsterFile << cardName << " " << typeOfCard << " " << cardAttribute << " " << cardLevel << " " << cardType << " " << cardSubType << " " << cardATK << " " << cardDEF << " " << numberOf;
break;
case 2:
cout << "Name: ";
cin >> cardName;
cout << "Type of Card: ";
cin >> typeOfCard;
cout << "Number Owned: ";
cin >> numberOf;
spellFile << cardName << " " << typeOfCard << numberOf;
break;
case 3:
cout << "Name: ";
cin >> cardName;
cout << "Type of Card: ";
cin >> typeOfCard;
cout << "Number Owned: ";
cin >> numberOf;
trapFile << cardName << " " << typeOfCard << numberOf;
break;
}
monsterFile.close();
spellFile.close();
trapFile.close();
trapFile.close();
}
|
here is part of the error log
Test_2.cpp: In function 'void cardSearch()':
Test_2.cpp:63:27: error: no match for 'operator>>' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}')
while (monstercardFile >> cardName >> typeOfCard >> cardAttribute >> cardLevel >> cardType >> cardSubType >> cardATK >> cardDEF >> numberOf)
^
In file included from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\string:53:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\locale_classes.h:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\ios_base.h:41,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:42,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from Test_2.cpp:1:
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_string.tcc:1441:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator>>(basic_istream<_CharT, _Traits>& __in,
^
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\basic_string.tcc:1441:5: note: template argument deduction/substitution failed:
Test_2.cpp:63:30: note: 'std::ofstream {aka std::basic_ofstream<char>}' is not derived from 'std::basic_istream<_CharT, _Traits>'
while (monstercardFile >> cardName >> typeOfCard >> cardAttribute >> cardLevel >> cardType >> cardSubType >> cardATK >> cardDEF >> numberOf)
^