Hi,
I am new to C++ .Net so please forgive me if the question sounds
silly.
I have implemented a class, as well as some client code that uses
the class. Now I decided that I want to add a GUI using C++ .net.
The problem is that I can't seem to link everything together.
I had the following files:
my_vector.h: contains the class implementation
test.cpp: contains the client code
Now I add the followings:
form1.h: for the GUI
form1.cpp: for the GUI
The following is a function that I want to call on my form's menu item
"Open". DTS is my class name. My question is, where should I place
the interface functions, such as this one, now? Do I declare it as a
member function of the Form1 class, or as a member function in the DTS
class, or should I just leave it stand-alone, as it is now? I tried
all options but I got some linking errors.
void GetInput(String *sFileName, DTS *dtsData)
{
const char* str = (const char*)
(Marshal::StringToHGlobalAnsi(sFileName)).ToPointe r();
// free string
Marshal::FreeHGlobal(IntPtr((void*)str));
ifstream ifIn(str);
double dblInputVal;
int cline = 0;
if (ifIn.fail())
{
cerr << "Error: cannot open " << str << endl;
exit(1);
}
while (!ifIn.eof())
{
ifIn >> dblInputVal;
dtsData->Insert(dblInputVal);
cline++;
}
cout << "# observations = " << cline << endl;
ifIn.close();
}
This is in form1.h:
private:
DTS *dtsData;
System::Void menuItem2_Click(System::Object * sender,
System::EventArgs * e)
{
OpenFileDialog *opFileDlg = new OpenFileDialog ();
opFileDlg->Filter="Text files (*.txt;*.dat)|*.txt;*.dat";
//if user has clicked on the Open button
if(opFileDlg->ShowDialog()==DialogResult::OK)
{
String *s=opFileDlg->FileName;
GetInputSimple(s, dtsData);
}
}
I am pretty lost now so any input would be appreciated!
Jessica