Anonymous Anonymous - 27 days ago
409 0

No description

C++

fileRead

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>


using namespace std;



int main()
{
    // stream position
    // streampos begin, end, size;
    int fileLines = 0, SIZE = 0;   // This is the size of the node array
    string tempArry[200] = { };  // Make a large empty array
    string node ="";    // Node name from file


    ifstream myfile ("temp.txt"); // Open the file as read input
    if(myfile.is_open())    // Check if open
    {
        while(!myfile.eof()) // Go from the start to end of the file
        {
            getline(myfile,node);
            if(node == "")  // Filter out empty lines in file
            {
                cout << "Empty line found: "<< fileLines+1<<endl;
            }
            else
            {
                tempArry[fileLines] = node;
                cout << "nodeID: "<< fileLines+1 << " - "<< tempArry[fileLines] <<" nr "<< SIZE<<endl;
                SIZE++;
            }
            fileLines++;
        }
        myfile.close();

        //cout << "size is: " << size << endl;
        cout << "lines are: " << fileLines << endl;
    }
    else cout << "Unable to open file\n";

    string nodeID[SIZE] = { };  // make the nodeID array
    copy(tempArry,tempArry+SIZE,nodeID);
    cout<<"nodeID size is: "<< nodeID[1] <<endl;

    return 0;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download