Hi guys,
im new in C++ programming and hope anyone could guide me to understand C++ and be able to code my assignment out :)

what the program does:
1. user inputs text file name,
2. user inputs key word
3. program goes about replacing character/strings in the text file with a formula(encrypt/decrypt)
4. output is displayed and save as another file name

so far i've done part 1, could some one guide me what should i use?
vectors or array to go about replacing or??

code as follows.....

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    ifstream fin;
    string name;
    string x;
    string s;
    char t
    int mark;
    
    
    do
    {
        cout << "Enter filename: ";
        cin >> x;
        cout << "You filename: " << x << endl;
        
        fin.open(x.c_str());
        
        if(x=="exit") {
            return(0);
           }

         
             if (!fin.good())
             {
                    cout << "File not found" << endl;
                    system("pause");
                    fin.clear();        
             }

             else
	         {

	                while(!fin.eof())
	                {
                             getline(fin, s);
                             cout << t << endl;

                    }
             }
             fin.close();
             fin.clear();
    }
    while(true);
    system("pause");
    return 0;

}
Member Avatar for iamthwee

Seeing as you are using std::strings I would look into using the string replace method.

Also beware of using eof to read files it has a hidden gotcha.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.