This is my first attempt at creating a program and I am having great problems. The program is meant to scan a file and increment a counter if specific words are found. Can anyone let me know where I'm going wrong,Thanks
I'm not surprised you're getting errors. Aside from the odd choice of using so many loops where one will do, you fail to close most of your blocks. Compare this with what you have and do try to learn from it:
using namespace std;
using std::cout;
using std::cin;
using std::ifstream;
int main()
{
string username; //Username that will be searched for
cout << "Marking Program"; //Start of program
cout << "Enter Students Username:"; //Get username off program user
cin >> username;
ifstream in("checkUserName.txt"); //Searching for students username
string search;
string line;
int n = 0;
if (!in) {
cerr<<"Username not found"<<endl; //If entered username not found display
return EXIT_FAILURE; //error message
}
else
if (in){
ifstream in(username.txt); //open students program
}
{ ifstream in("markScheme.txt"); //open the marking scheme file
if (!in){
cerr<<"Mark Scheme not found"<<endl; //If file not found display error
return EXIT_FAILURE;
}
}
if (!getline(cin, search)) {
!=++n;
}
while (getline(in, line)) {
if (line.find(search) == string::npos)
++n;
}
yeah what i want the program to do is use the strings i've created in the markScheme.txt to see if they are in the students file that I open. Does that make sense!
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.