Okay I have a small problem. I have to load a file which contains (for example):
a bleh
b blah
c bloh
So basically it contains a character(1,2,3,..etc) followed by a string (bleh,blah,bloh etc..)
I have to create a struct which should contain a char and a string, they will represent the character and string from the file respectivly(sp?).
What I am required to do after is basically read a new file (with random text in it) which will inturn use the struct I have created to "encode" the contents of my new file with the string of the sctruct file.
My code so far is:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct letterTocode
{
char letter;
string to_code;
};
int main (int argc, char *argv[])
{
ifstream codefile("blahblehbloh.txt");
vector<letterTocode> toCode;
string line;
ifstream myfile,encoded_file;
if (blahblehbloh.is_open())
{
while(!blahblehbloh.eof())
{
getline (blahblehbloh,line);
cout << line << endl;
}
blahblehbloh.close();
}
encode(myfile);
print(encoded_file);
return 0;
}
I am going to have a new function called encode() which will:
- Read the struct
- "encode" the new file with the codefile(blahblehbloh.txt)
Right now I am stuck at the creating of my Struct itself, I've read a few Struct examples, they had similar layout for the Struct but I do not think that the way I layed out my Struct is correct. As of this moment I don't see how I will be able to read the single character, store it in the struct char and then read the string (on the same line) and store that in the string in Struct and then use that Struct to encode the new file opened.
>_>