c++ Windows forms, file reading (total noob)

Few days ago I started my term paper and I want to do it in windows forms, but so far it's total headache ~_~

for starter, I want to read file on button click
top of Form header file
1
2
3
4
#pragma once
#include <iostream>
#include <fstream>
//#include <string> 

... lots of **** and then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 using namespace std;
//			string line, tag;
//			size_t pos, pos2;
			fstream duomf("DB/tags.db",ios::in);
			if(duomf.open())
				label2->Text="FILE IS OPEN";
/*			while(getline(duomf, line))
			{
				pos = line.find("|");
				pos2 = line.find("\n");
				tag = line.substr(0, pos);
			} */
			duomf.close();
			 }

in console application that would be correct, but I get
1
2
3
4
5
6
7
8
c:\documents and settings\kyoshiro\desktop\folders\3semestras\c++\programavimas cpp\nd\tager\tager\tager\Form2.h(136): error C2661: 'std::basic_fstream<_Elem,_Traits>::open' : no overloaded function takes 0 arguments
          with
          [
              _Elem=char,
              _Traits=std::char_traits<char>
          ]

Build FAILED.

on Visual Studio 2010

well ok... I put in arguments, so it's if(duomf.open("DB/tags.db",ios::in)) on 6th line but now error is
1
2
3
4
c:\documents and settings\kyoshiro\desktop\folders\3semestras\c++\programavimas cpp\nd\tager\tager\tager\Form2.h(135): error C2451: conditional expression of type 'void' is illegal
          Expressions of type void cannot be converted to other types

Build FAILED.


So whats wrong with my head?
I know I could finish my term paper in few days if I did program as console application, but I don't want to do so.
closed account (3hM2Nwbp)
1
2
3
4
5
6
7
8
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
using namespace std;
fstream duomf;
duomf.open("DB/tags.db",ios::in); //<-- Returns void
if(!duomf) //<-- operator!
{/*failed*/}
else
{/*Succeeded*/}


http://cplusplus.com/reference/iostream/ifstream/open/

http://cplusplus.com/reference/iostream/ios/operatornot/
Last edited on
lol.. I tried that before, but I got dozens of errors :D
now I checked it again and noticed that I included Form2.h in wrong place.
Damn >.< VS with those stupid stdafx files and untrained users head

Anyways, thanks for helping me Luc Lieber o(^-^)o
Last edited on
closed account (3hM2Nwbp)
You can switch off the use of precompiled headers in Visual Studio if you wish. It's in your project properties.
Topic archived. No new replies allowed.