By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,491 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Read/write C++ glopal text files problem

P: 2
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.
pleeeeeeeeeeeeeeeeeeeeez 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<iostream>
#include"scanner.h"
#include<fstream>
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<iostream>
#include"scanner.h"
#include<fstream>
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::app );

myfile1.get(ch);
myfile2<<"Tokens_Type"<<"\t\t\t"<<"Line Number"<<"\t\t"<<"Lexmes"<<endl;
do
{
T1 = S1.getT();
switch(T1.TokenType)
.
.
.
}while

---------------------and in scaner.h i write this:

typedef enum { TOK_IDENT,TOK_IL,KW_ELSE,KW_IF,KW_INT,KW_RETURN,KW _VOID,KW_WHILE,TOK_SEMICOLON,
TOK_PLUS,TOK_STAR,TOK_SLASH,TOK_EQ,TOK_GT,TOK_GT_E Q,TOK_LT,TOK_LT_EQ,TOK_NOT_EQ,TOK_ASSIGN,TOK_LBRAC E,
TOK_RBRACE,TOK_LBRACKET,TOK_RBRACKET,TOK_LPAR,TOK_ RPAR,TOK_COMMA,TOK_MINUS,END,ERROR}TokenTypes;
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,lexeme 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_fstream<char,struct std::char_traits<char> > myfile1" (?myfile1@@3V?$basic_fstream@DU?$char_traits@D@std @@@std@@A)
Debug/test_scanner.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

test_scanner.exe - 2 error(s), 0 warning(s)
----------------------------------------------------------------


thanks for help!!!!
Nov 13 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.