-
createing my constructer
ok the class is file in a header file and im makeing the constructor I am trying to make a bunch of strings to equal 0 heres what I have tried:
file::file()
{
file_one = "0";
}
trying to compile is says:
Lvalue required in function file::file()
so then I tried:
file::file()
{
file_one = '0';
}
and it said the same thing I am new to this what is going on?
-
What did u declare file_one to be? If you want, you can declare them to be the null terminating character.
file_one="\0";
-
I did that
and it still said the same thing it can be \0 or just a 0 or anything like that
-
what is file_one... (as golfinguy4 stated)
show the rest of you code.
I don't think your problem is there... did you terminate your class with a semicolon? Is your class implementation and declaration in the same file?
show code... use [ code ] [ /code ] tags...
-
ok heres the code
Heres file.h
Code:
#ifndef file_var
#define file_var
class file
{
public:
file();
~file();
void encrypt ();
void decrypt ();
char EncryptChar (char ch);
void EncryptString (char *str);
protected:
char file_one[256];
char file_two[256];
char contents[1000];
char key[5];
};
#endif
heres main_01.cpp
Code:
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include "file.h"
file::file()
{
file_one="\0";
file_two="\0";
contents="\0";
key="\0";
}
char file::EncryptChar(char ch)
{
key[0] = key[1] + key[3];
key[4] = key[0] * key[2];
ch = key[4];
return ch;
}
void file::EncryptString(char *str)
{
while (*str != '\0') *str = EncryptChar(*str++);
}
void file::encrypt()
{
cout<<"Enter Files Name"<<endl;
cout<<":";
cin.getline(file_one, 256, '\n');
cout<<"Enter File to Save it to"<<endl;
cout<<":";
cin.getline(file_two , 256, '\n');
cout<<"Enter 5 Digit Key"<<endl;
cout<<":";
cin.getline(key, 5, '\n');
/* Open File */
ifstream ein;
ein.open(file_one);
while(ein.eof() != 1)
{
int x = 0;
x++;
ein>>contents[x];
}
/* Encrypt */
EncryptString(contents);
/* Save */
ofstream eout;
eout.open(file_two);
for(int x = 0; x != 1000; x++)
{
eout<<contents[x];
}
eout.close();
/* Finished */
cout<<"Encryption completed..."<<endl;
cout<<file_one<<" was encypted to "<<file_two<<endl;
cout<<"The key is "<<key<<endl;
Sleep(2500);
exit(0);
}
and when I try to compile it on borland 5.5 this happens:
! Error E2277 .\main_01.cpp 11: Lvalue required in function file::file()
! Error E2277 .\main_01.cpp 12: Lvalue required in function file::file()
! Error E2277 .\main_01.cpp 13: Lvalue required in function file::file()
! Error E2277 .\main_01.cpp 14: Lvalue required in function file::file()
-
ahhh.. got it...
They are arrays.
You need the [] and a reference array point
Code:
int i;
for (i=0; i < 256;++i)
file_one[i]='\0';
-
oh man
no that didnt work what is the Lvalue it still says that
-
>file_one="\0";
memset ( file_one, 0, 256 );
And include either string.h or cstring when you work with C strings. :)
-Prelude
-
still...
doesnt work I have tried what you said I included both of them did the memset thing didnt work I did the for loop thing with and without the memset thing didnt work what is the Lvalue thing if I knew what it was talking about...
-
It compiles fine for me when I use memset, here's the constructor code that worked:
Code:
file :: file()
{
memset(file_one,'\0',256);
memset(file_two,'\0',256);
memset(contents,'\0',1000);
memset(key,'\0',5);
}
An Lvalue is a variable or chunk of memory that allows assignment to itself. So you can assign to an integer i, but not to an expression (i + 3). You can't assign a string to an array of char directly except during initialization:
char string[] = "This is a string"; // This works
string = "This is another string"; // Bzzzt! Illegal
-Prelude
-
oh man
oh I was doing it wrong thanks so much man!