Help With Program To Input/Output File And Find String

Hello Everyone!

Beginner C++ student here, first ever programming class. Currently learning string functions and input/output files. Trying to put a program together which will look at an existing file for the name 'john' or 'JOHN' in both upper and lower case. Then output the results into another file.

We were told we could convert all instances of the name to upper or lower case (I chose upper) so the the program would output instances of the name regardless what case it is in.

I noted below where I am having one of my problems and I may have more somewhere else which I can't see yet. Wondering if any of you kind folks can help me out with this.

Below is what I have so far and I noted the errors being returned as well.

Thank you so very much for your time and help!!!

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
 
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

bool die(const string & msg);

bool input(string & s, const string & prompt);

bool open(ifstream & fin, const string & fileName);

bool open(ofstream & fout, const string & fileName);

//bool name(const string & line);

bool convert(string & str, string & converted);

int main() {

	string inName, outName;
	ifstream fin;
	ofstream fout;

	if (!input(inName, "Name of input file: "))
		die("I can't read the name of the input file");

	if (!open(fin, inName))
		die("I can't open " + inName + " for output");

	if (!input(outName, "Name of output file: "))
		die("I can't read the name of the input file");

	if (!open(fout, outName))
		die("I can't open " + outName + " for output");

	for (string converted; getline(fin, converted);) {

		if (convert(converted)) //<---***HAVING AN ISSUE HERE***
			fout << converted << endl;


	}
	if (fin.rdstate() != (ios::failbit | ios::eofbit))
		die("Input file " + inName + " terminated input incorrectly");

	fout.close();
	if (!fout)
		die("Output file " + outName + "had a problem with writing or closing");

	fin.close();

	cout << "read from " << inName << ", wrote to " << outName << ", ok" << endl;

}// main

bool die(const string & msg){
	cout << "Fatal error: " << msg << endl;
	exit(EXIT_FAILURE);
}

bool input(string & s, const string & prompt) {

	cout << prompt;
	return getline(cin, s) ? true : false;
}

bool open(ifstream & fin, const string & fileName){

	fin.open(fileName);
	return fin ? true : false;

}

bool open(ofstream & fout, const string & fileName){

	ifstream tin(fileName);
	if (tin) return false;
	fout.open(fileName);
	return fout ? true : false;
}

//bool name(const string & line){

	
	//return line.find("john") != UINT_MAX;

//}

bool convert(string & str, string & converted)
{
	for (short i = 0; i < str.size(); ++i)
		converted += toupper(str[i]);
	return converted.find("john") != UINT_MAX;
}


Errors I am getting:

Error 1 error C2660: 'convert' : function does not take 1 arguments Line 40
Warning 2 warning C4018: '<' : signed/unsigned mismatch Line 93
3 IntelliSense: too few arguments in function call Line 40
Last edited on
You're only passing one parameter into convert, but you've told your compiler that function needs two parameters.

Also, what's the point of your functions return a bool in die when you don't return anything?
Topic archived. No new replies allowed.