I started this code, and it does encode the text, however it only does the first line of text and repeats it. It is also encoding spaces.

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
  ifstream fin;

  string fileName;
  cout << "What file do you want to use for input? ";
  getline(cin, fileName);
  fin.open(fileName.c_str());

  string s;

while (true)
  {
    if (!fin.good()) break;
    getline(fin, s);
        string s = "Hello, World"; // an example
    for (int i = 0; i < s.length(); i++) // for each char in the string...
    s[i]++;
    cout << s << endl;
  }

  fin.close();

   return 0;
}

Lines 20 and 21. You have two strings named s with different scopes. You have read a line from the file and stuck that line into one of them in line 20, then you have placed "Hello, World" into the other one in line 21, then on lines 22 and 23, you are manipulating string s. But do you know WHICH string s you are manipulating? I fail to see the need for the string on line 21 anyway. You're reading from a file, right?

As far as manipulating spaces when you don't want, check out the cctype library. You can test what kind of character a character is and act accordingly (i.e. manipulate only printable characters). An "if" statement combined with a function from cctype, then placing line 23 within the code to execute if the if statement is true might be what you are looking for.

Thank you, figured it out with the library.

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.