How can I compile c++ code without getting errors?

Any time I want to add a class in my project through the editor everything seems fine until I add some random code and try to compile. I get various errors like -

Error 1 error C1083: Cannot open include file: ‘MyGame.generated.inl’: No such file or directory C:\Users\Algirdas\Documents\Unreal Projects\MyGame\Source\MyGame\MyGame.cpp 5 1 MyGame

Error 2 error : Failed to produce item: C:\Users\Algirdas\Documents\Unreal Projects\MyGame\Binaries\Win64\UE4Editor-MyGame.dll C:\Users\Algirdas\Documents\Unreal Projects\MyGame\Intermediate\ProjectFiles\ERROR MyGame

Error 3 error MSB3073: The command ““C:\Program Files\Unreal Engine\4.1\Engine\Build\BatchFiles\Build.bat” MyGame2Editor Win64 Development “C:\Users\Algirdas\Documents\Unreal Projects\MyGame\MyGame.uproject” -rocket” exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets

I also tried removing all the code that I added and compiling. Now the editor does not open because it is asking for a compiled module. What could be the problem?

nvm, apparently I cannot build with the editor open. No problems now