i am trying to write a program that takes information from a file and reads it and then does some kind of encryption, simple as adding one to it

I have it reading the file,
but how would i go about readings the characters as int's
and then adding a number to them?

"Hi blah blah" = 234234 345634634 345345345 345345345
I want this to be stored in their number form + some number.

11 Years
Discussion Span
Last Post by Ancient Dragon

char data type is a small int whose value is between -126 and 127. So do do what you want just loop through the array and add 1 to the char value.

char str[] = "Hi blah blah";
// add 1 to the first character, syntax is idental to int

Thanx, hmm but i still have one problem...

I need to read the text from a file.

So is there a way to read from the file and
then put that data into an array?


after reading the string from a text file to the encryption like I posted earlier. Do you know how to read files ? In c++ use the ifstream class to read a text file. Here is an example of how to read/write text files.


This is the code i have so far, which only displays "file.txt" and displays it.


using namespace std;

const int SIZEMAX = 81;

void read(fstream &);

int main()
       fstream dataFile;
       dataFile.open("file.txt", ios::in);
      cout << "The file does not exist. Please check your file." 
      <<    endl;

          return 0;


       cout << endl << "Done" << endl;

    return 0;


       void read(fstream &file)
        char line[SIZEMAX];
           while( file >> line)
               cout << line << endl;

p.s. is there a way to tab in this chat box?


Well, this isn't really encryption, but I can't really figure out what you're trying to do to obtain the numbers. This just prints out the ASCII value for each character by casting to int.

int i = 0;
while(myString[i]) {
    std::cout << static_cast<int>(myString[i]) << " ";
std::cout << std::endl;

This code is fairly clear; it is trivial to modify it to fit into your read() function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.