Card Database Assistance

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)
^
Last edited on
In the cardSearch function, do you mean to read the files as input, ifstream instead of ofstream?
monstercardFile is an ofstream object and so you need to use the insertion operator << and not the extraction operator >> (as a rule of thumb the arrows indicate whether the data is going to the stream or coming from the stream). So check throughout your program that the operators and corresponding fstream objects match.

You seem to have chucked in bunches of cin ignore, clear, get at various points in your code. Do make sure you fully understand what each of these methods do.

Return 0 will end the entire program but if you wish to (a) give the user the option to go back to the start menu and choose from New Cards, Search Cards or Exit Program again or (b) move on to some other procedures before quitiing main() then a bool variable to quit the switch-case statements is more efficient. Here's something I posted recently on this: http://www.cplusplus.com/forum/beginner/201427/

Finally, please use code-tags for posting code
Thank you for the help gunnerfunner. I have tried the code tags but couldn't figure out how to use them it never turned out right.
How might I create an edit function to edit the data of a specified card?
Thank you for the help gunnerfunner. I have tried the code tags but couldn't figure out how to use them it never turned out right.

Edit your topic and wrap your code in [code] (Your code) [/code] tags.
You can't edit the data of a specified card under your current program as it doesn't capture the card object. To do that you first have to set up a Card class with data-members such as suit and face and then instantiate objects of this class inside your program. Then if your Card class has appropriate setter methods you can change the attributes of the specified card through these methods.
A recent example of the Card class on this forum that I'd contributed to: http://www.cplusplus.com/forum/beginner/201221/
Alrighty thank you for all your assistance.
Topic archived. No new replies allowed.