reading from txt file

i have an assignment that is supposed to take points from a txt file and plot them out i have this code so far but keep getting errors can anyone help me.


#include "ccc_win.h"
#include <fstream>


int ccc_win_main()
{

ifstream myfile ("hshape.txt"); //open my filestream

while (! myfile.eof())
{
//Asking for name of file
cout << "Enter the file name: ";
cin.getline(myfile,Point,'\n');
myfile >> value >> Point;
cout <<Point<<endl;
}

return 0;

}
Make an MyFile.txt in the program folder, then run this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

void safeFn()
{
    ifstream myFile("MyFile.txt");
    int nInputValue;

    for(int n = 1; n <= 10; n++)
    {
        myFile >> nInputValue;

        if (myFile.fail())
        {
            break;
        }

        cout << n << " - " << nInputValue << endl;
    }
}

int main(int nNumberofArgs,char* pszArgs[])
{
    safeFn();

    system("PAUSE");
    return 0;
}
And this will suit your needs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;

int main(int nNumberofArgs,char* pszArgs[])
{
    char filename[256];
    cout << "Enter the name of file you want to open: ";
    cin.getline(filename,256);

    for(int s = 0;s != '\n';s++)
    {
        if(filename[s] == NULL)
        {
            filename[s] = '.';
            filename[s + 1] = 't';
            filename[s + 2] = 'x';
            filename[s + 3] = 't';
            filename[s + 4] = NULL;
            break;
        }
    }
    cout << "Opening and reading contents of '" << filename << "'" << endl;

    ifstream File(filename);

    for(int n = 1;;n++)
    {
        char object[256];
        File.getline(object,256);

        if(File.fail())
        {
            break;
        }

        cout << n << " - " << object << endl;
    }

    system("PAUSE");
    return 0;
}
Make sure the file is in the project folder
Topic archived. No new replies allowed.