matching one string to another

I know that I can use istringstream to match the text from one text file to another but I just cant wrap my head around how that would look in code. I need help with this because my project is due tomorrow night and I need to spen the day with my mom. its her 85th birthday and its her first birthday since my dad passed. can someone please help me?

[code]
//
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <istream>
#include "Assignment1.h"

//using namespace std;
//-----------------------------function declarations

//string OpenLogFile();
//void GetLogFileName(string&)
//int OpenLogFile(ofstream&);


//-----------------------------variables
//Student MyStudents;
//Student MyGrades;
//ofstream OutLogName;
string LogFileName;
string TextToWrite;
string StudentTextFile;
string ClassHoursTextFile;
string DataTextFile;
string LogTextFile;


//-----------------------------main body
int main()
{
cout << "Welcome to the GradeCaculator Deluxe." << endl;
cout << "Enter the name of the STUDENT file including the extension :: " << endl;
getline (cin, StudentTextFile);
cout << StudentTextFile << endl;
cout << "Enter name of the CLASS HOURS file including the extension :: " << endl;
getline (cin, ClassHoursTextFile);
cout << "Enter name of the DATA file including the extension :: " << endl;
getline (cin, DataTextFile);
cout << "Enter name of the LOG file including the extension :: " << endl;
getline (cin, LogTextFile);
GetStudentList ();
// GetClassHours ();
OpenOutputFile ();
// OpenLogFile ();


}//end main
//--------GetStudentList
string GetStudentList()
{
string FirstName;
string LastName;
int StudentId;
int NumberOfGrades;
string ClassName;
char Grade;
int Index = 0;
int LineIndex = 0;
ifstream StudentFile;
student MyStudents;
grades MyGrades;
StudentFile.open(StudentTextFile.c_str());
if(!StudentFile.is_open())
{
exit(EXIT_FAILURE);
}
GetClassHours ();

while (StudentFile >> FirstName >> LastName >> StudentId >> NumberOfGrades)
{
MyStudents.FirstName = FirstName;
MyStudents.LastName = LastName;
MyStudents.StudentId = StudentId;
MyStudents.NumberOfGrades = NumberOfGrades;
for (int Index = 0; Index < NumberOfGrades; ++Index)
{
(StudentFile >> ClassName >> Grade);
//======================================================
///======this is where I think the math search should go
//======================================================

MyGrades.ClassName = ClassName;
MyGrades.Grade = Grade;
}//end for
}//end while
cout << MyStudents.FirstName << ", " << MyStudents.LastName << ", " << MyStudents.StudentId << ", " << MyStudents.NumberOfGrades << endl;
cout << MyGrades.ClassName << ", " << MyGrades.Grade << endl;
TextToWrite = "Students.txt successfully opened\n";
OpenLogFile (TextToWrite);
return TextToWrite;
}//end GetStudentList
//--------GetClassHours
string GetClassHours()
{

//int Grades MyHours [15];
ifstream HoursFile;
//struct grades MyGrades;
//cout <<"Enter the file name for the list of Class Hours, including the extension::" << endl;
//getline(cin, File2);
HoursFile.open(ClassHoursTextFile.c_str());
if(!HoursFile.is_open())
{
exit(EXIT_FAILURE);
}
TextToWrite = "Hours.txt successfully opened for reading.\n";
OpenLogFile (TextToWrite);
return TextToWrite;
}//end GetClassHours
//-------OpenOutputFile
string OpenOutputFile()
{
ifstream OutputFile;

OutputFile.open(DataTextFile.c_str());
if(!OutputFile.is_open())
{
exit(EXIT_FAILURE);
}
TextToWrite = "Data.txt has been successfully opened for reading.\n";
OpenLogFile (TextToWrite);
return TextToWrite;
}//end GetClassHours
//-------OpenLogFile
string OpenLogFile(string TextToWrite)
{
ofstream OutLogFile;
OutLogFile.open(LogTextFile.c_str());
if (!OutLogFile.is_open())
{
exit(EXIT_FAILURE);
}//end if
cout << "The file has been successfully opened for reading.\n";
//string TextToWrite = "andy";
OutLogFile << TextToWrite << endl;
OutLogFile.close();
return TextToWrite;
}//end OpenLogFile
//int OpenLogFile(ofstream& OutLogName, string& LogFileName, string TextToWrite)
//{
//ofstream OutLogName;
//OutLogName.open(LogTextFile.c_str());
//if (!OutLogName)
//{
//cout << "File FAILED to open....Program Terminated" << endl;
//return 1;
//}
//OutLogName << TextToWrite << endl;
//return 0;
//}//end OpenLogFile





[\code]
66 post and you haven't mastered code tags ?

http://www.cplusplus.com/articles/jEywvCM9/

your missing
using namespace std;

I'm having trouble wrapping my head around your code. Maybe you should start smaller and get it working a little at a time.

Do you have to use istringstream, or is that just something you would use if it would work ?
Last edited on
Well for some reason it would not allow me to "format" my code.
I am just looking for the easiest way to match strings.
Tell me quickly what your trying to match.

I saw your comment

1
2
3
//======================================================
			///======this is where I think the math search should go
			//====================================================== 


but i'm not clear on what your searching.
Last name & first
or
StudentId
or maybe both

I am just looking for the easiest way to match strings.


1
2
3
if(str1 == str2) {
it's a match!
} 
I need to search for a match of course numbers and then get the credit hours of one and calculate the GPA based on other info. I'm gonna try the == operator.
Topic archived. No new replies allowed.