I've been tasked with reading in multiple emails that are stored in a single archive file and then scanning it to find certain things. My problem now is that I seem to only be reading in the first of the many individual files stored in the single archive.

The "archive" file is just plain text, nothing too special about it. I can read it in notepad.

the very last cout statement just starts printing jibberish until an illegal access is made, so i just have it print one beyond the char array bounds.

here is my code:

#include <regex>
#include <iostream>
#include <vector>
#include <fstream>

using namespace std::tr1;
using namespace std;

int main()
	string inputfilename = "ham";

	string text_file;

	ifstream ifs;
	string temp;
	getline(ifs, temp); // to get some initial stuff out of the way.
		getline(ifs, temp);
		text_file += temp + '\n';
	char* search = new char[text_file.size() + 1];
	search[text_file.length() + 1];
	int i = 0;
	for(; search[i] != '\0'; i++)
		cout << search[i];

	cout << search[i+1];

It reads gibberish because you failed to validate that the file was opened on line 16, which I can see that it was not. Your compiler should have produced an error message saying the std::stream.open() does not take a std::string object as the first parameter. ifs.open(inputfilename.c_str()); Then check if the file was actually opened. if( !ifs.is_open() )

The for loop on lines 29 and 30 print out the first file correctly. It seems as though the second file and onward doesn't get placed in the text_file string.

have to see the file. Maybe there is a Ctrl+Z at the end of the first file which makes ifstream think its at end-of-file.

It's a 16 megabyte text file... kind of hard to post. I have narrowed it down though. Lines 19 to 23 work properly. I tried cout on text_file and everything is stored in it properly. The problem is copying it from text_file to the search char array. It only copies the first file into the char array. Maybe what I'll try to do is analyze the char array of the one file, then make text_file equal to a substring that starts with the 2nd file (and so on) and copy that into the char array again (it should copy the entire second file into the char array). then keep doing that over and over until text_file doesn't have anything left in it.