Code can't compile !

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std;

int checkpseudo(string text);
void checkMachine(ofstream& outputST, ofstream& outputLT1 , int& LC , int& L , string text0 , string text1 , string text2);

void checkLabel(ofstream& outputST, int& LC , int& L , string text0 , string text1 , string text2);
void checkDS(ofstream& outputST, int& LC , int& L , string text0 , string text1 , string text2);
void checkDC(ofstream& outputST, int& LC , int& L , string text0 , string text1 , string text2);
void checkLTORG(ofstream& outputLT1 , ofstream& outputLT , ifstream readcard , int& LC);
void checkEND(ofstream& outputLT1 , ofstream& outputLT , ifstream readcard, int& LC);


int _tmain(int argc, _TCHAR* argv[])
{
int L = 0 , LC = 0 , i = 0;
string field[3];
char read[100];
char *pch;
ifstream readcard;
ofstream output2 , outputST, outputLT1 , outputLT;
readcard.open("input1.txt");
output2.open("input2.txt");
outputST.open("ST.txt");
//readcard.unsetf(ios::skipws);
if(!readcard)
{
cerr << "Open file \"input1.txt\" Error" << endl;
exit(100);
}
if(!output2)
{
cerr << "Open file \"input2.txt\" Error" << endl;
exit(101);
}
if(!outputST)
{
cerr << "Open file \"ST.txt\" Error" << endl;
exit(102);
}
while(!readcard.eof())
{
//cin >> read;
readcard.getline(read,100);
//====================== Field Filter ================
pch = strtok(read," ");
i = 0;
while (pch != NULL)
{
//cout << pch << endl;
field[i] = pch;
pch = strtok(NULL, " ");
i++;
}
//====================================================
if(i == 2)
{
field[2] = field[1];
field[1] = field[0];
field[0] = "";
}
if(i == 1)
{
field[2] = "";
field[1] = field[0];
field[0] = "";
}
cout << left << setw(10) << field[0] << setw(10) << field[1] << setw(10) << field[2] << endl;
switch(checkpseudo(field[1]))
{
case 1 : checkDS(outputST, LC , L , field[0] , field[1] , field[2]);break;
case 2 : checkDC(outputST, LC , L , field[0] , field[1] , field[2]);break;
case 3 : checkLabel(outputST, LC , L , field[0] , field[1] , field[2]); break;
case 4 : break;
case 5 : break;
case 6 : checkEND(outputLT1 , outputLT , readcard , LC);break;
//case 7 : checkLTORG(outputLT1 , outputLT , readcard , LC );break;
case 8 : checkLabel(outputST, LC , L , field[0] , field[1] , field[2]); break;
case 0 : checkMachine(outputST, outputLT1 , LC , L , field[0] , field[1] , field[2]);break;
}
output2 << left << setw(10) << field[0] << setw(10) << field[1] << setw(10) << field[2] << endl;
field[0] = "";
field[1] = "";
field[2] = "";
}
return 0;
}
//========================================================================
int checkpseudo(string text)
{
if(text == "DS")
{return 1;}
else if(text == "DC")
{return 2;}
else if(text == "EQU")
{return 3;}
else if(text == "USING")
{return 4;}
else if(text == "DROP")
{return 5;}
else if(text == "END")
{return 6;}
else if(text == "LTORG")
{return 7;}
else if(text == "START")
{return 8;}
else
{return 0;}
}
void checkMachine(ofstream& outputST, ofstream& outputLT1 , int& LC , int& L , string text0 , string text1 , string text2)
{

outputLT1.open("outputLT1.dat");
string s2;
char relocation = 'R';

string s1(text1,text1.length()-1,1);
if (s1 == "R")
L = 2;
else L = 4;

int cut = text2.rfind("=");
if(cut != string::npos)
{
s2 = text2.substr(cut+1);
outputLT1 << left << setw(10) << s2 << setw(10) << L << setw(10) << relocation << endl;
}

if(text0 != "")
{
outputST << left << setw(10) << s2 << setw(10) << LC << setw(10) << L << setw(10) << relocation << endl;
}

LC = LC + L;


}
//========================================================================
void checkLabel(ofstream& outputST, int& LC , int& L , string text0 , string text1 , string text2)
{
int tempLC = LC;
char relocation = 'R';
if(text0 != "")
{
if(text1 == "EQU" || text1 == "START")
{
L = 1;
if(text1 == "EQU" && text2 != "*")
{
LC = atol(text2.c_str()); // Strint to int
relocation = 'A';
}
else
{
relocation = 'R';
}
}
else
{
L = 4;
}
outputST << left << setw(10) << text0 << setw(10) << LC << setw(10) << L << setw(10) << relocation << endl;
LC = tempLC;
}
}

void checkLTORG(ofstream& outputLT1 , ofstream& outputLT , ifstream readcard , int& LC )
{
readcard.open("outputLT1.dat");
outputLT.open("outputLT.txt");

int i;
string field[4];
char read[100];
char *pch;

while(LC%8 != 0)
{
LC++;
}

readcard.getline(read,100);
//====================== Field Filter ================
pch = strtok(read," ");
i = 0;
while (pch != NULL)
{
//cout << pch << endl;
field[i] = pch;
pch = strtok(NULL, " ");
i++;
}
//====================================================

if(i == 3)
{

outputLT << left << setw(10) << field[0] << setw(10) << LC << setw(10) << field[1] << setw(10) << field[2] << endl;
}

if( i == 4)
{
outputLT << left << setw(10) << field[0] << setw(10) << field[1] << setw(10) << field[2] << setw(10) << field[3] << endl;
}




}

//=============================================================================
/*

1>------ Build started: Project: assem, Configuration: Debug Win32 ------
1>Build started 2/9/2554 21:01:10.
1>InitializeBuildStatus:
1> Touching "Debug\assem.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> assem.cpp
1>c:\documents and settings\administrator\desktop\assem\assem\assem.cpp(55): warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\string.h(197) : see declaration of 'strtok'
1>c:\documents and settings\administrator\desktop\assem\assem\assem.cpp(61): warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\string.h(197) : see declaration of 'strtok'
1>c:\program files\microsoft visual studio 10.0\vc\include\fstream(890): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const std::basic_ifstream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>c:\documents and settings\administrator\desktop\assem\assem\assem.cpp(205): warning C4552: '*' : operator has no effect; expected operator with side-effect
1>
1>Build FAILED.


What I'm doing wrong ? / I'dont understand what error is ?
void checkLTORG(ofstream& outputLT1 , ofstream& outputLT , ifstream readcard , int& LC )
Standard streams are non-copyable. Pass by reference.

warning C4552: '*' : operator has no effect; expected operator with side-effect
I can't find this one. Which line is the error pointing to?
Last edited on
Thx for ur answer , but I still don't know how to solve this . can you edit this to show me? Plz.
If you add #define _CRT_SECURE_NO_WARNINGS to the top of the file, immediately after the first include...

1
2
3
4
5
#include "stdafx.h"
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
...


it will shut up the "function or variable may be unsafe" warnings.
Last edited on
Topic archived. No new replies allowed.