hello I'm new to this and will like some help. I will like to create a visual program with to command buttons, the first to open a file by having the user choose the file and the second command button is to open the file and read in the text. here is what I have which gives 2 errors and a warning:

void CUltraReadDlg::OnOpen() 
{
    //MY CODE STARTS HERE

    typedef struct tagOFN { //ofn
        LPCTSTR lpstrFilter;
        LPCTSTR lpstrInitialDir;
    } OPENFILENAME;

    CFileDialog m_ldFile(TRUE);

    // Initialize the starting directory

    m_ldFile.m_ofn.lpstrInitialDir="C:\\Temp\\";

    // Show the file open dialog and capture the result

    if (m_ldFile.DoModal() == IDOK)
    {   m_sResults = m_ldFile.GetPathName() + m_ldFile.GetFileName();
        UpdateData(FALSE);
    }

void CUltraReadDlg::OnRun() 
    // //MY CODE STARTS HERE
#include <fstream>
#include <iostream>
#include <string>         
using namespace std;

int main()
{ 
    ifstream m_fileRead(m_sResults);
    if (m_fileRead.fail()) {
        cerr << "unable to open file for reading." <<endl;
        exit(1);
    }

    string nextToken;
    while (inFile >> nextToken){
        cout << "Token: " << nexttoken << endl;


    }

    m_fileRead.close();
    return 0;

}

    //END OF MY CODE
}

What are the errors and warnings?? We can't read your mind or see your computer, so you have to be specific and tell us.

here are the errors

Compiling...
UltraReadDlg.cpp
c:\program files\microsoft visual studio\vc98\include\errno.h(29) : warning C4518: 'extern ' : storage-class or type specifier(s) unexpected here; ignored
c:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2143: syntax error : missing ';' before 'string'
c:\program files\microsoft visual studio\vc98\include\errno.h(29) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

UltraRead.exe - 2 error(s), 1 warning(s)

Those errors seem to be coming from Microsoft include files. I suspect its caused by something in your own program. Post the complete UltraReadDlg.cpp file, or at least the first 20-30 lines that show all the includes. You might also have to inspect the contents of stdafx.h file, if you have changed it since the compiler originally generated it.

The structure of your code is like this:

void CUltraReadDlg::OnOpen()
{
	// ...
	void CUltraReadDlg::OnRun()

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

	int main()
	{
		//...
	}
}

How could that ever compile?

Those errors seem to be coming from Microsoft include files. I suspect its caused by something in your own program. Post the complete UltraReadDlg.cpp file, or at least the first 20-30 lines that show all the includes. You might also have to inspect the contents of stdafx.h file, if you have changed it since the compiler originally generated it.

Here is the file

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.