Code error

Hello,
I have been having a problem coding up a program for security, just to test.
this error has been coming up:
main.cpp could not convert `(&checkfile)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(&lok))))' to `bool'

This is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <fstream>
using namespace std;

int main()
{
string checkfile;
string abc;
string lok = "e=mc2x";
cout << "Checking Security File....\n";
ifstream file;
  file.open ("file.arce");

  while (!file.eof())
  {
    getline (file, abc);
    checkfile.append (abc); // Added this line
  }

Sleep(30);
if (checkfile=lok);
{
cout << "Security Check Complete! Software is secure.\n";
goto start;
}
cout << "Security Check Failed. Please reinstall or actually purchase program.";
start:
Sleep(1);
}

Can someone please help me? I am using Dev-CPP 4.9.9.2 with MingW that came with it.
EDIT: if you search
1
2
3
4
5
6
7
8
ifstream file;
  file.open ("file.arce");

  while (!file.eof())
  {
    getline (file, abc);
    checkfile.append (abc); // Added this line
  }

Something like this, a old post will come up.
Last edited on
Two errors here:
if (checkfile=lok);
a) the comparison operator == should be used, rather than the assignment operator =

b) the line should not end with a semicolon.

This code is not recommended:
1
2
3
4
5
    while (!file.eof())
    {
        getline (file, abc);
        checkfile.append (abc); 
    }

because even if the getline at line 3 fails, the next line is still executed.

This would be the safer way:
1
2
3
4
    while (getline (file, abc))
    {
        checkfile.append (abc); 
    }


One more thing, the version of Dev-C++ you are using is very old, if I remember correctly it was last updated in 2005. I would strongly recommend you upgrade to the latest version, Orwell Dev-C++ 5.4.1
http://orwelldevcpp.blogspot.co.uk/
Thanks Chervil, BTW i used to have orwell Dev-C++ but it crashed and had mingw64 where mine is mingw32. And Dev-C++ 4.9.9.2 is handy to have as my ancient Windows 95 PC has the same version on it. But thanks for the code, worked perfectly!
Well, I do agree it can be useful to have the same software on each computer.
Anyway, there's a choice of compiler with the Orwell version, both 32 and 64 bit versions are available.

As for it crashing, that's unfortunate, I suggest you try it again soon, as new versions are made available very regularly.
Ok thanks.
Now I have a new problem.
It compiled ok, but now trying to add a else statement is stuffing up.
Here's the code segment.
1
2
3
4
5
6
7
8
if (checkfile==lok);
{
cout << "Security Check Complete! Software is secure.\n";
goto start;
}
else {
cout << "Security Check Failed. Please reinstall or actually purchase program.";
}

The errors I am getting are main3.cpp expected primary-expression before "else"
main3.cpp expected `;' before "else"
Last edited on
You still need to remove the semicolon from the end of your if statement on line 1, it isn't needed.
Thanks! it works now.
Topic archived. No new replies allowed.