Below I have a snippet of my code. Basically, I am wondering why there is a difference in output when I individually print contextFile[0] and contextFile[1] versus through a for loop.
In contextfile.txt (which is the value of target_file_name in this case), I have the following:
hickory dickory dot had a little farm you feel me.
Here is the code:
cin >> target_file_name; ifstream fileExist(target_file_name); if (fileExist) { int count = 0; int contextSize = 1000; int keySize = 1000; char *contextFile; char *keyFile; contextFile = new char[contextSize]; keyFile = new char[keySize]; string command; fileExist >> contextFile[count]; while (!fileExist.fail()) { count++; fileExist >> contextFile[count]; } cout << "printing individual: " << contextFile[0] << contextFile[1]; cout << "Printing the contextfile array: " << endl; for (int i = 0; i < count; i++) { cout << contextFile[count]; } When I print individually, I get hi, which is the correct output.
When I print through the for loop, I just get straight ================.
Why is there a difference?