I have in my programm three files: SCANNER.CPP,tst _scanner.cpp and scaner.h
i need read and write from text file which is glopal. how i can do it?
the strange things if i put all programm in one file it is working as good.but whene i use three files it is have error(not define the glopal text file in some file).
i am using many wayes to solve this probleme(i define the glopal text file out of main or enter and enter of getT() or outer of it or the top of any file is .cpp or using 'extern' and....)but i did not get the solve.
pleeeeeeeeeeeee eeeeeeeez i neeeeeeeeed to know how i do it? if i can opening the text file to be glopal in constructor of my class that good for mee.
NOTE: i need to use this hider of function: Tokens Scanner::getT()
I am writing in SCANNER.CPP this lines code:
#include<iostre am>
#include"scanne r.h"
#include<fstrea m>
static char ch;
using namespace std;
extern fstream myfile1;
int lineo=1;
Tokens Scanner::getT()
{
.
.
.
}
-------------and in main file tst_scanner.cpp i write this
#include<iostre am>
#include"scanne r.h"
#include<fstrea m>
using namespace std;
int line=1;
static char ch;
//extern fstream myfile1;
int main()
{
//extern fstream myfile1;
fstream myfile2, myfile1; //static fstream myfile1,myfile2 ;
Scanner S1;
Tokens T1;
myfile1.open( "C:\\fcode.txt" , ios::in | ios::out );
myfile2.open( "C:\\fscan.txt" , ios::in | ios::out|ios::a pp );
myfile1.get(ch) ;
myfile2<<"Token s_Type"<<"\t\t\ t"<<"Line Number"<<"\t\t" <<"Lexmes"<<end l;
do
{
T1 = S1.getT();
switch(T1.Token Type)
.
.
.
}while
---------------------and in scaner.h i write this:
typedef enum { TOK_IDENT,TOK_I L,KW_ELSE,KW_IF ,KW_INT,KW_RETU RN,KW_VOID,KW_W HILE,TOK_SEMICO LON,
TOK_PLUS,TOK_ST AR,TOK_SLASH,TO K_EQ,TOK_GT,TOK _GT_EQ,TOK_LT,T OK_LT_EQ,TOK_NO T_EQ,TOK_ASSIGN ,TOK_LBRACE,
TOK_RBRACE,TOK_ LBRACKET,TOK_RB RACKET,TOK_LPAR ,TOK_RPAR,TOK_C OMMA,TOK_MINUS, END,ERROR}Token Types;
class Tokens
{
friend class Scanner;
public:
TokenTypes TokenType ;
char* lexeme;
int newval;
};
class Scanner
{
public:
//Scanner(); // constructor
Tokens getT();//----------- return object of class (Tokens).
//-----------And Tokens return TokenType,lexem e and line
};
I have some time this ERROR or NO ERROR but the file not read in scanner.cpp
--------------------Configuration: test_scanner - Win32 Debug--------------------
Linking...
Scanner.obj : error LNK2001: unresolved external symbol "class std::basic_fstr eam<char,struct std::char_trait s<char> > myfile1" (?myfile1@@3V?$ basic_fstream@D U?$char_traits@ D@std@@@std@@A)
Debug/test_scanner.ex e : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
test_scanner.ex e - 2 error(s), 0 warning(s)
----------------------------------------------------------------
thanks for help!!!!
i need read and write from text file which is glopal. how i can do it?
the strange things if i put all programm in one file it is working as good.but whene i use three files it is have error(not define the glopal text file in some file).
i am using many wayes to solve this probleme(i define the glopal text file out of main or enter and enter of getT() or outer of it or the top of any file is .cpp or using 'extern' and....)but i did not get the solve.
pleeeeeeeeeeeee eeeeeeeez i neeeeeeeeed to know how i do it? if i can opening the text file to be glopal in constructor of my class that good for mee.
NOTE: i need to use this hider of function: Tokens Scanner::getT()
I am writing in SCANNER.CPP this lines code:
#include<iostre am>
#include"scanne r.h"
#include<fstrea m>
static char ch;
using namespace std;
extern fstream myfile1;
int lineo=1;
Tokens Scanner::getT()
{
.
.
.
}
-------------and in main file tst_scanner.cpp i write this
#include<iostre am>
#include"scanne r.h"
#include<fstrea m>
using namespace std;
int line=1;
static char ch;
//extern fstream myfile1;
int main()
{
//extern fstream myfile1;
fstream myfile2, myfile1; //static fstream myfile1,myfile2 ;
Scanner S1;
Tokens T1;
myfile1.open( "C:\\fcode.txt" , ios::in | ios::out );
myfile2.open( "C:\\fscan.txt" , ios::in | ios::out|ios::a pp );
myfile1.get(ch) ;
myfile2<<"Token s_Type"<<"\t\t\ t"<<"Line Number"<<"\t\t" <<"Lexmes"<<end l;
do
{
T1 = S1.getT();
switch(T1.Token Type)
.
.
.
}while
---------------------and in scaner.h i write this:
typedef enum { TOK_IDENT,TOK_I L,KW_ELSE,KW_IF ,KW_INT,KW_RETU RN,KW_VOID,KW_W HILE,TOK_SEMICO LON,
TOK_PLUS,TOK_ST AR,TOK_SLASH,TO K_EQ,TOK_GT,TOK _GT_EQ,TOK_LT,T OK_LT_EQ,TOK_NO T_EQ,TOK_ASSIGN ,TOK_LBRACE,
TOK_RBRACE,TOK_ LBRACKET,TOK_RB RACKET,TOK_LPAR ,TOK_RPAR,TOK_C OMMA,TOK_MINUS, END,ERROR}Token Types;
class Tokens
{
friend class Scanner;
public:
TokenTypes TokenType ;
char* lexeme;
int newval;
};
class Scanner
{
public:
//Scanner(); // constructor
Tokens getT();//----------- return object of class (Tokens).
//-----------And Tokens return TokenType,lexem e and line
};
I have some time this ERROR or NO ERROR but the file not read in scanner.cpp
--------------------Configuration: test_scanner - Win32 Debug--------------------
Linking...
Scanner.obj : error LNK2001: unresolved external symbol "class std::basic_fstr eam<char,struct std::char_trait s<char> > myfile1" (?myfile1@@3V?$ basic_fstream@D U?$char_traits@ D@std@@@std@@A)
Debug/test_scanner.ex e : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
test_scanner.ex e - 2 error(s), 0 warning(s)
----------------------------------------------------------------
thanks for help!!!!