Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About iansane

  • Rank
  1. reading zahlmans post again. I feel like I've made a lot of progress towards understanding this. Thanks to all
  2. Quote:EasilyConfused: for(size_t i=0;i<memblock.size();++i) std::cout << int(memblock) << std::endl; This helps a lot with the txt file. I can easily convert it to binary or ascii and back again. The jpg file however gives me negative numbers. Is there a table for whatever type of encoding it uses? If I write a simple algorithm that mixes them up and then one to put them back in order, and figure out how to rewrite the file in it's original encoding, do I even need to be able to understand the strange symbols of the jpg? If I write the decimal representations to a file with the jpg extension will my system automatically encode it so I have a copy of the picture? I'll go and test that out to see.
  3. Ok I'll have to read this a few more times so it sinks in. Sorry to be dificult. What is confusing me is, how do I manipulate bits if I don't have bits. I was expecting to see 1's and 0's I'm getting text instead of the binary that the text represents. Actually as far as the ASCII I can and have used a table to translate that before so it's not a problem. But for the jpg, it is not ASCII and not 1's and 0's. Do I need to learn the encoding used for jpg? I thought if I open and read a file of any type with the binary tag the output displayed on the screen would be 1's and 0's since I thought that is what binary is. Thank you for the info. Looks like I need to understand some other things about binary and my system better before I can do this.
  4. Tried it this way and got the same thing. Undecypherable symbols for jpg actual text for txt file. If I type "bla bla bla" in a test.txt file and open it, the out put is "bla bla bla", not binary. Any ideas? Thanks
  5. Thanks all of you for your detailed explanations and the error checking tips. I rewrote the whole program according to some advice from another forum and what I get now is not binary. What I get for a text file is the actual text (not binary), and for a jpg, I get the same as what I get if I open a jpg with notepad. example: ÿØÿà JFIF H H ÿá Exif MM * ÿÛ C ÿÛ CÿÀ à€" ÿÄ ÿÄ f !1AQaÁð$q‘¡±á4Ñ%Dñ 5Td‚&ERt¢6U„ÂÒâ"#3BCbe¤´FSVWc’”ÄÔ'2suv…•–7GfµÿÄ ÿÄ D !1AQaq‘¡ð±ÁÑáñ"$2BRb‚4Dr’²ÂÒ¢â#3Ã%ÿÚ ? 一…3€( ] ¼'8™Âpð0™Àp!7€( ]0›Âpð ¼'8 ¼@P&ðœ8át&ð œ „œ@ „œ@ „œ@ ˜Mà pœ( “€( 8€ 8€œ@ !' € ' èJ …„ ( I'll try it your way now and post if I have trouble with it. But I should clarify what I'm trying to do here. I am trying to get the 1's and 0's that make the file. (totally unencoded binary). Isn't that what I need if I want to encrypt, decrypt, or even try to hide a file in a file? I'm sure there is a lot that I am missing since I don't know a lot about encoding, (did some 64 bit encoding on paper with a chart once) , so am I going about this the right way?
  6. Thanks OldGuy I figured out the push_back way after a few errors about converting char to char. I'll try this way too. Thanks a lot
  7. Hi, I want to read the binary of a file into a vector so I can make an encryption and decryption algorithm to encrypt the binary. Not sure if that is the right way to do it. I am trying to use the following code from cplusplus.com, but to write it to a vector instead of a memory block. Can anyone tell me how to do this? I tried vector.push_back(memblock) and it seems to be working but I get an error at run time saying the program needs to close. I don't think I'm understanding how it works. Do I need to read into another variable to use with push_back? // reading a complete binary file #include <iostream> #include <fstream> using namespace std; ifstream::pos_type size; char * memblock; int main () { ifstream file ("example.txt", ios::in|ios::binary|ios::ate); if (file.is_open()) { size = file.tellg(); memblock = new char [size]; file.seekg (0, ios::beg); file.read (memblock, size); file.close(); cout << "the complete file content is in memory"; delete[] memblock; } else cout << "Unable to open file"; return 0; }
  8. Thanks Endurion, I pretty much figured that out, but now it is putting the commas in? I don't know what might have changed that part of it but it is waiting till line 4 now. BTW part of my problem was I had the wrong line number. I'll keep playing around and see if I can figure it out. I want it to write the commas in to the vector but when it reads I want it to not display the commas. Thanks for the help
  9. current line number? I know I want it to start reading at the third line. Not sure how to tell it to ignore the first 2 lines and only record after the second one. is there c++ syntax for line number? Something like "if (line number == 3) {//record into vector"} ?
  10. Hi, I know this isn't gaming but I'm learning the basics of c++ before I dive into gaming. I have a readFile() function that reads from a csv and displays it on screen with ","'s replaced with spaces. It reads it into a vector along with the first two lines which are collum headings. After displaying, it asks the user if they want to add entries and if yes, calls appendFile() which adds to vector and then calls writeFile(). I need my readFile() to skip the first two lines and start reading into the vector at line 3 so when I append it won't add the headings again. Can anyone tell me how to do that? Thanks Here's my readFile(): void readFile(string) { cout << "Type the name of the file.\n"; getline(cin, fileName); fstream file( fileName.c_str() ); string text; stringstream parse (stringstream::in | stringstream::out); while (getline(file, text, ',')) { parse << text; data.push_back(text); data.push_back(" "); } for (iter = data.begin(); iter != data.end(); ++iter) cout << *iter; char yesNo; cout << "\n\n"; cout << "Do you want to add another entry to the file?\n"; cin >> yesNo; if (yesNo == 'y' || yesNo == 'Y') { appendToFile(fileName, data); } }
  11. how do I mark this as solved or can I do that?
  12. sorry, I was getting all kinds of errors for other things like the concantination I was trying to do so it had me confused. I tried starting fresh and not useing the quotes and it works. Thanks for the reply.
  13. Hi, I am writing a program to read from a file. I want to ask the user for the file name to open. I have tried to use the basic open file code from cplusplus.com and it won't work unless I specify the file name in the code. If I have them enter a file name, I then need to add "'s to it? Either way, I get errors if I use char or string for the input file name. Can anyone show me how to do this? Code from cplusplus.com with my variable for the fileName: #include <iostream> #include <fstream> using namespace std; int main () { char fileName[256]; cout << "Enter a file"; cin >> fileName; //tried string instead of char with getline(cin, fileName) //but same problem as below. ofstream myfile; myfile.open (fileName); //should have quotes around the file name // ex. ("file.text") // but how to put //them in? Won't let me concatenate them in myfile << "Writing this to a file.\n"; myfile.close(); return 0; } Thanks for any help understanding this. I have heard that it is best to use this method for open and close because it is explicit so if I can make it work this way, I would prefer it.
  14. ok sorry, wasn't sure how to do that. Thanks for the tip.
  15. well sorry for that. The error said ignore_line, not ignoreline and sure enough, part of the code containing the ignore_line() function was left off. The whole thing looked so confusing and was hard to see where it starts and ends since I have no idea how most of the code works. Here's what I left off at the top. template <typename CharT> std::streamsize ignore_line ( std::basic_istream<CharT>& in, bool always_discard = false ) { std::streamsize nread = 0; if ( always_discard || ( in.rdbuf()->sungetc() != std::char_traits<CharT>::eof() && in.get() != in.widen ( '\n' ) ) ) { // The stream is good, and we haven't // read a full line yet, so clear it out in.ignore ( std::numeric_limits<std::streamsize>::max(), in.widen ( '\n' ) ); nread = in.gcount(); } return nread; }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!