outfile.close();
}
void update()
{
string temp;
string st_txt1;
string st_txt2;
ofstream seek1;
ifstream temp1;
seek1.open("Inventory Database.txt");
temp1.open( "temp.txt");
cout<<"Enter the text that you want to edit\n";
getline(cin, st_txt1);
cout<<"Enter the text that you want to replace\n";
getline(cin, st_txt2);
while (getline(temp1, temp))
{
if (temp.find(st_txt1) != string::npos)
{
temp.replace(temp.find(st_txt1), st_txt1.length(), st_txt2);
cout << temp << endl;
}
seek1 << temp << endl;
}
cout<<endl<<"Edit success.\n";
}
void deletedata()
{
string temp;
string st_txt1;
string st_txt2;
ofstream seek1;
ifstream temp1;
seek1.open("Inventory Database.txt");
temp1.open( "temp.txt");
cout<<"Enter the text that you want to delete\n";
getline(cin, st_txt1);
while (getline(temp1, temp))
{
if (temp.find(st_txt1) != string::npos)
{
temp.replace(temp.find(st_txt1), st_txt1.length(), "-1");
cout << temp << endl;
}
seek1 << temp << endl;
}
cout<<endl<<"Edit success.\n";
}
void searchdata()
{
ifstream outfile("Inventory Database.txt");
string answer1;
string item_id;
string item_name;
string item_des;
string item_categ;
string item_manufac;
string item_sellpri;
string item_costpri;
string item_unitin;
string item_unitsold;
string item_yearofdateintro;
string item_monthofdateintro;
string item_dayofdateintro;
cout << "Which data would you like to see ?" << endl;
getline(cin,answer1);
cout << endl;
if (answer1 == "item id")
{
cout << "ID : " << item_id << endl;
}
else if (answer1 == "item name")
{
cout << "Item Name : " << item_name << endl;
}
else if (answer1 == "item description")
{
cout << "Item Description : " << item_des << endl;
}
else if (answer1 == "item category")
{
cout << "Item Category : " << item_categ << endl;
}
else if (answer1 == "item manufacturer")
{
cout << "Item Manufacturer : " << item_manufac << endl;
}
else if (answer1 == "item sell price|item sellprice")
{
cout << "Item Sellprice : " << item_sellpri << endl;
}
else if (answer1 == "item costprice|item cost price")
{
cout << "Item Costprice : " << item_costpri << endl;
}
else if (answer1 == "item unitin|item unit in")
{
cout << "Item UnitIn : " << item_unitin << endl;
}
else if (answer1 == "item unit sold|item unitsold")
{
cout << "Item unit sold : " << item_unitsold << endl;
}
else if (answer1 == "item year")
{
cout << "Item year of date introduced : " << item_yearofdateintro << endl;
}
else if (answer1 == "item month")
{
cout << "Item month of date introduced : " << item_monthofdateintro << endl;
}
else if (answer1 == "item day")
{
cout << "Item day of date introduced : " << item_dayofdateintro << endl;
}
else
cout << "No record found in database" << endl;
}
void bye()
{
cout << "THANK YOU FOR USING US" << endl;
cout << "FEEL FREE TO COME BACK " << endl;
So my searchdata function are supposed to be a simple if else statement to display data on which the user choose to see. But somehow the value did not show on the screen.
In your searchdata function, you create lots of empty strings. You never fill them, You never put any data in the strings. That's why the output is blank. Because you have empty strings.
Even if I already input the value in the main function ?
If you create a variable in one function, and then create another variable with the same name in a different function, they're different variables. Putting some data into one of them doesn't do anything to the other.
So how do I read the existing data from inside the text file ?
yeah I just started learning about the language for like a month since. I guess I still have a lot to do so btw thanks for helping and I'll be sure to learn more