Badly need help: (Unresolved external symbol) & (More than one instance of overloaded function matches argument list)

This program is supposed to read an input file stream and transfer the file to an output stream. It's also supposed to catch all instances of "cin <<" and replace them with "cin >>". It's also supposed to replace "cout >>" with "cout << " The number of whitespaces between the cin/cout streams and the insertion/extraction operators is supposed to be an indeterminate amount for each case. Here's 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
200
201
#include <fstream>
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

//Rewrites the file from the input stream to the output stream with all instances of "cin <<" and "cout >>"
//corrected. There can be any number of whitespaces between cin/cout and the insertion/extraction operator
void file_transfer(ifstream& in_stream, ofstream& out_stream);

//Takes the next character to be proccessed from file and checks if it changes whether the text is transitioning
//from being inside quotation marks to being outside quotation marks or vice versa.
//in_quotes is true if the current text is in quotes and false otherwise assuming that the variable input for parameter
//in_quotes gives the correct state the text is in at the time the function is called (i.e. whether the text is in quotes or outside of quotes)
void check_quotes(char next, bool in_quotes);

//clears white spaces inbetween two non-whitespaces in an input file stream
void clear_spaces(ifstream& in_stream);

int main()
{
	ifstream in_stream;
	in_stream.open("test3.txt");
	if(in_stream.fail())
	{
		perror("Input stream failed to open");
		cin.get();
		exit(1);
	}

	ofstream out_stream;
	out_stream.open("test2.txt");
	if(out_stream.fail())
	{
		perror("Input stream failed to open");
		cin.get();
		exit(1);
	}

	file_transfer(in_stream, out_stream);

	in_stream.close();
	out_stream.close();

	cout << "End of the program.\nEnter key to continue.";
	cin.get();

    return 0;
}

void file_transfer(ifstream& in_stream, ofstream out_stream)
{
	char next;
	long i(0);
	bool in_quotes = false;
	cin.get(next);
	while(!in_stream.eof())
	{
		switch(next)
		{
			case 'c':
			{
				if(!in_quotes)
				{
					i=1;
					out_stream << next;
				}
			}
			case 'i':
			{
				if(i==1)
				{
					i=2;
				}
				else
				{
					i=0;
				}
				out_stream << next;
			}
			case 'n':
			{
				if(i==2)
				{
					i=3;
				}
				else
				{
					i=0;
				}
				out_stream << next;
				clear_spaces(in_stream);
			}
			case 'o':
			{
				if(i==1)
				{
					i=6;
				}
				else
				{
					i=0;
				}
				out_stream << next;
			}
			case 'u':
			{
				if(i==6)
				{
					i=7;
				}
				else
				{
					i=0;
				}
				out_stream << next;
			}
			case 't':
			{
				if(i==7)
				{
					i=8;
				}
				else
				{
					i=0;
				}
				out_stream << next;
				clear_spaces(in_stream);
			}
			case '<':
			{
				if(i==3)
				{
					i=4;
				}
				else if(i==4)
				{
					i=0;
					out_stream << ">>";
				}
				else
				{
					out_stream << next;
				}
			}
			case '>':
			{
				if(i==8)
				{
					i=9;
				}
				else if(i==9)
				{
					out_stream << "<<";
				}
				else
				{
					out_stream << next;
				}
			}
			default:
			{
				if(i==4)
				{
					out_stream << '<';
				}
				else if(i==9)
				{
					out_stream << '<';
				}
				out_stream << next;
				i=0;
			}
		}
		cin.get(next);
		check_quotes(next, in_quotes);
	}
}

void check_quotes(char next, bool in_quotes)
{
	if(next == '"')
	{
		in_quotes = !in_quotes;
	}
	return;
}

void clear_spaces(ifstream& in_stream)
{
	char next;
	do
	{
		in_stream.get(next);
	}while(isspace(next));
	in_stream.putback(next);
	return;
}


I realize it's messy. I was wondering if there's an easier way to implement the function file_transfer because although I think I have the right idea I think that there's got to be an easier way of doing this than how I attempted to do it thus far. Secondly, I am getting a function because of my file_transfer function. The error is:

1>test2.obj : error LNK2019: unresolved external symbol "void __cdecl file_transfer(class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?file_transfer@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ofstream@DU?$char_traits@D@std@@@2@@Z) referenced in function _main
1>C:\Users\Paul\documents\visual studio 2010\Projects\test2\Debug\test2.exe : fatal error LNK1120: 1 unresolved externals

Before I compile there's a red squiggly line under the function call to file_transfer. When I hover over it it says "More than one instance of of overloaded function "file_transfer" matches the argument list". I thought this meant that there was another function with the same name that takes the same arguments so I experimented with changing the name of it (in the function call, header, and definition) and that hasn't solved the problem.

Even if someone comes up with an alternate suggestion for how to implement the file_transfer function, I would still like to know, if possible, why I am getting a compilation error as the code is right now so that I would know for future references what it is that I did wrongly.

Thank you for taking the time to read this.
closed account (DSLq5Di1)
You'll probably kick yourself when you see this one..

1
2
3
4
5
6
void file_transfer(ifstream& in_stream, ofstream& out_stream);

void file_transfer(ifstream& in_stream, ofstream out_stream)
{
    ...
}
I think the easiest way;

1. copy the original with a different name and work on the copy. you can use this copy method; http://blog.emptycrate.com/node/264

2. create two char pointers, say chPtrBack, chPtrForward. they both will start at the beginning of the file. but chPtrForward will iterate chPtrBack+3 everytime. because cin, the size of the smallest comparison element is 3.

3. in a do ..while loop, chPtrForward will use strcmp(str1, str2) to find if there is any cin or cout. if there is, it will call a replace function, where chPtrBack will check if it's a cin or a cout, and replace << or >>. And it will return back with a "done" flag.

4. the while loop will end at the end of the file.

Last edited on
thanks for your guys' contribution. Sloppy, you saved me hours of drudgery, thank you. I've just started using streams so it hasn't singed into my head yet that you need to call by reference. Muratagenc, that sounds like an interesting approach and I thank you for taking the time but I'm not acquainted with pointers at this moment. This is the code that works well enough for my satisfaction:

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <fstream>
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

//Rewrites the file from the input stream to the output stream with all instances of "cin <<" and "cout >>"
//corrected. There can be any number of whitespaces between cin/cout and the insertion/extraction operator
void file_transfer(ifstream& in_stream, ofstream& out_stream);

//Takes the next character to be proccessed from file and checks if it changes whether the text is transitioning
//from being inside quotation marks to being outside quotation marks or vice versa.
//in_quotes is true if the current text is in quotes and false otherwise assuming that the variable input for parameter
//in_quotes gives the correct state the text is in at the time the function is called (i.e. whether the text is in quotes or outside of quotes)
void check_quotes(char next, bool in_quotes);

//clears white spaces inbetween two non-whitespaces in an input file stream
void clear_spaces(ifstream& in_stream);

int main()
{
	ifstream in_stream;
	in_stream.open("test3.txt");
	if(in_stream.fail())
	{
		perror("Input stream failed to open");
		cin.get();
		exit(1);
	}

	ofstream out_stream;
	out_stream.open("test2.txt");
	if(out_stream.fail())
	{
		perror("Input stream failed to open");
		cin.get();
		exit(1);
	}

	file_transfer(in_stream, out_stream);

	in_stream.close();
	out_stream.close();

	cout << "End of the program.\nEnter key to continue.";
	cin.get();

    return 0;
}

void file_transfer(ifstream& in_stream, ofstream& out_stream)
{
	char next;
	long i(0);
	bool in_quotes = false;
	in_stream.get(next);
	while(!in_stream.eof())
	{
		switch(next)
		{
			case 'c':
			{
				if(!in_quotes)
				{
					i=1;
					out_stream << next;
				}
				break;
			}
			case 'i':
			{
				if(i==1)
				{
					i=2;
				}
				else
				{
					i=0;
				}
				out_stream << next;
				break;
			}
			case 'n':
			{
				if(i==2)
				{
					i=3;
					clear_spaces(in_stream);
				}
				else
				{
					i=0;
				}
				out_stream << next;
				break;
			}
			case 'o':
			{
				if(i==1)
				{
					i=6;
				}
				else
				{
					i=0;
				}
				out_stream << next;
				break;
			}
			case 'u':
			{
				if(i==6)
				{
					i=7;
				}
				else
				{
					i=0;
				}
				out_stream << next;
				break;
			}
			case 't':
			{
				if(i==7)
				{
					i=8;
					clear_spaces(in_stream);
				}
				else
				{
					i=0;
				}
				out_stream << next;
				break;
			}
			case '<':
			{
				if(i==3)
				{
					i=4;
				}
				else if(i==4)
				{
					i=0;
					out_stream << " >>";
				}
				else
				{
					if(i==9)
					{
						out_stream << '>';
					}
					out_stream << next;
					i=0;
				}
				break;
			}
			case '>':
			{
				if(i==8)
				{
					i=9;
				}
				else if(i==9)
				{
					i=0;
					out_stream << " <<";
				}
				else
				{
					if(i==4)
					{
						out_stream << '<';
					}
					out_stream << next;
					i=0;
				}
				break;
			}
			default:
			{
				if(i==4)
				{
					out_stream << ' <';
				}
				else if(i==9)
				{
					out_stream << '>';
				}
				out_stream << next;
				i=0;
			}
		}
		in_stream.get(next);
		check_quotes(next, in_quotes);
	}
}

void check_quotes(char next, bool in_quotes)
{
	if(next == '"')
	{
		in_quotes = !in_quotes;
	}
	return;
}

void clear_spaces(ifstream& in_stream)
{
	char next;
	do
	{
		in_stream.get(next);
	}while(isspace(next));

	in_stream.putback(next);
	return;
}
sounds good. you know what they say; if it works, don't touch it ;)
Topic archived. No new replies allowed.