Search
 
SCRIPT & CODE EXAMPLE
 

CPP

search update delete files in c++

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
    int k=0;
    string line;
    string find;
    char name[25];
    int id=0; 
    float gpa=0;

    ofstream myfile;
    myfile.open("data.txt");

    while(k!=3){

        cout<<"press 1 for adding data"<<endl;
        cout<<"press 2 for update "<<endl;

        cin>>k;

        if(k==1)
        { 
            cout<<"enter ID "<<endl;
            cin>>id;

            cout<<"enter Name"<<endl;
            cin>>name;

            cout<<"enter GPA "<<endl;
            cin>>gpa;

            myfile<<name<<endl;
            myfile<<id<<endl;
            myfile<<gpa<<endl<<endl<<endl;
        }

        if(k==2)
        {

            cout<<"name u want to update "<<endl;
            cin>>find; 
            ifstream file;

            file.open("data.txt");
            while (!file.eof() && line!=find)
            {

                getline(file,line);
            }

            cout<<"enter ID "<<endl;
            cin>>id;

            cout<<"enter Name"<<endl;
            cin>>name;

            cout<<"enter GPA "<<endl;
            cin>>gpa;
            myfile<<name<<endl;
            myfile<<id<<endl;
            myfile<<gpa<<endl<<endl<<endl;
        }
        if(k==3){
            myfile.close();
        }
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: write a code that adds two number 
Cpp :: cpp executing without console 
Cpp :: how to use dec in C++ 
Cpp :: make_move_iterator 
Cpp :: stock a file in a vector cpp 
Cpp :: ue4 find component c++ 
Cpp :: cannot open include file unreal 
Cpp :: declare dictionary cpp 
Cpp :: xmake run with arg 
Cpp :: c++ remove last element from vector 
Cpp :: how to specify how many decimal to print out with std::cout 
Cpp :: return the index where maximum element in a vector 
Cpp :: print 5 table in c++ 
Cpp :: print queue c++ 
Cpp :: remove () not working c++ 
Cpp :: BMI Calculator Program in C++ 
Cpp :: cout.flush() in c++ 
Cpp :: cpp float to int 
Cpp :: comment in c++ 
Cpp :: sfml mouse button pressed 
Cpp :: replace komma with space C++ 
Cpp :: find length of array c++ 
Cpp :: apply pca to dataframe 
Cpp :: default access modifier in c++ 
Cpp :: how to find length of character array in c++ 
Cpp :: sort vector in descending order 
Cpp :: c++ count number of element in vector 
Cpp :: rand c++ 
Cpp :: const char to string 
Cpp :: sieve of eratosthenes algorithm in c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =