Hey all, first off, I'm NOT looking for answers to my homework by any means. I am rather looking for guidance. I want to understand the material rather than just have the solution handed to me. Therefore, here's my problem: I have a project where I have to read info from a data file, print it out in two separate parallel (1D) arrays, and that's pretty much it for now. Here's my code (remember, I am a beginner with a capital B) so please any advice and/or guidance would help tremendously. Thanks for your help.

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

const int NUM_WORDS = 154;

typedef string PigWords[NUM_WORDS];
typedef string EngWords[NUM_WORDS];

void PrintDictionary (int, const PigWords, const EngWords);

int main()
{
    ifstream inFile;

    PigWords pigs;
    EngWords engs;

    inFile.open("pigData.txt");

    if ( !inFile )
    {
        cout << "Error: Data file could not be opened" << endl;
        return (EXIT_FAILURE);
    }



    PrintDictionary (NUM_WORDS, pigs, engs);

    inFile.clear();
    inFile.close();

    return (EXIT_SUCCESS);
}

void PrintDictionary (int NUM_WORDS, PigWords pigs, EngWords engs)
{
    return;
}

Your code doesn't seem to be doing anything with the file once you read it in.

Say I had..

ifstream inData;
inData.open("packets.txt");
string line;

while (getline(inData, line)) 
{
       cout << line << endl;
}

The condition in the while loop remains true as long as the end of the file has not been reached. So in this example it will print out each line of the file until the end of file has been reached.

For example if in packets.txt we had..

My name is bob.
Hello bob!

After this code has printed the second line the condition in the while loop would become false and cause us to fall out of it.

Hopefully this helped you out. You should be able to apply these ideals to your problem.

I'll try it out and get back to you, but anyway, thank you so much for your help. I appreciate it a ton.

Don't forget code tags. It makes it easier for us to help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.