Apple, can we please have this?
Before you say it, I know this functionality already exists on the iPad. It’s just not very convenient. And convenience is kinda the whole point…
Pleeeeeeeeease?!
A friend of mine who just started learning C++ ran into a build error on his first program, which looks likes this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
This is the type of program you’d expect to see in just about any beginner’s C++ tutorial. What they usually don’t tell you is that this program won’t work in Microsoft Visual C++ without some additional configuration.
You can see the full error message in the Output pane, which is normally docked at the bottom of the window. Here is the rest of the message:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1> ConsoleApplication1.cpp 1>e:\code\visual c++ projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> Add directive to 'StdAfx.h' or rebuild precompiled header 1>e:\code\visual c++ projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Right away, there’s a problem with line 1. We know this because the line number is shown in parentheses after the filename. This is followed by the error code, which is C4627, and the rest of the error message. Visual C++ is pretty clear about what the problem is, but if you’re completely new to programming or to C++ then these words probably don’t mean much to you.
Beginners often get flak in programming circles for not reading or understanding error messages – in this case, a search for error c4627 would get you pretty far – but I think this is a bit unfair. We don’t normally expect anyone to read, much less understand, something in another language. There’s a lot of vocabulary here for a beginner to learn. So let’s break this error message down, starting with:
'#include <iostream>' skipped when looking for precompiled header use
Basically, the compiler didn’t bother to include the file we asked it to (it skipped it). What’s a “precompiled header?” It’s just another C++ file that has some code that we need in it, plus it’s already been compiled. We don’t need to compile it again because it is not going to change. (i.e., iostream will probably never be updated.)
Add directive to 'StdAfx.h' or rebuild precompiled header
A “directive” is an instruction we can give to the compiler. In our program, #include <iostream> instructs the compiler to look in the iostream header file for things like cout. We could add another directive like this to stdafx.h, another header file which is included in our project under “Header Files.”
(By the way, are we having fun yet? Get used to debugging errors if you want to become a programmer. i.e. don’t get discouraged. At least 50% of my time at work is spent debugging errors.)
Visual C++ reports not one but two problems with our code. The second error message comes from line 10, error code C1010:
unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
Here, the compiler is telling us it kept looking for our precompiled header ’til it hit the end of the file. It never found it, but it thinks it could be in stdafx.h. Unless you’ve been reading ahead, it won’t find it there either. It doesn’t know either way because we never told it to look there. i.e., we didn’t #include "stdafx.h" at the beginning of our file.
Want to know something freaky? Our program compiles without a hitch in Code::Blocks.
This is because new project’s in Visual C++ are configured to use precompiled headers, but not in Code::Blocks. That tutorial we got our code from probably assumed we weren’t using Microsoft tools but standard tools like GNU Make. In fact, Code::Blocks normally comes with a version of GNU specifically for Windows called MinGW (Minimalist GNU for Windows). That solves that mystery.
But how do we fix our program? I’ll tell you how to change your project’s configuration to get up and running quickly, but I’ll also tell you how to take advantage of precompiled headers if you want to do things the Visual C++ way.
First, if you want Visual C++ to behave like Code::Blocks, right click on your project in the Solution Explorer pane and go to Properties:
On the left side of the properties window, drill down to Configuration Properties > C/C++ > Precompiled Headers. Change the first option, simply named Precompiled Header, from “Use (/Yu)” to “Not Using Precompiled Headers,” then click OK.
Now you can run your program!
If you want to use precompiled headers instead, simply change the first line of your program:
#include "stdafx.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Then add the missing directive to stdafx.h:
#pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> #include <iostream>
Now, run your program and celebrate. You are a programmer.
Did you see the console window appear for a brief second and then disappear? Typically, console programs do their thing and then close immediately. You can tell your program to pause and wait by adding a call to system("pause") before the line return 0:
#include "stdafx.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
system("pause");
return 0;
}
That way you’ll have time to admire your beautiful program before closing it.
Although this has been documented elsewhere (see here and here), the instructions are mostly geared towards people who want to use a gamepad for one player and a keyboard/mouse for another player. If you are fortunate enough to have two gamepads for your PC, then playing Left 4 Dead in split screen mode is surprisingly easy to set up.
Step 1: Download this Xbox 360 controller emulator by Evaldas Jocys. The file you want is named something like x360ce.App-2.0.2.158.zip, give or take the version number. (Sound familiar? This is the same thing we did for Dead Rising 2.)
Step 2: Extract the zip archive to your Left 4 Dead executable directory, which will be something like C:\Program Files (x86)\Steam\steamapps\common\left 4 dead.
Step 3: Run the x360ce executable file. When the program launches, it will prompt you to create the x360ce.ini file. This is the file that holds the configuration settings for the program. It will also prompt you to create the xinput1_3.dll file. This is the library file that gets compiled along with the configuration settings and will enable your gamepad to work with the game. Click Yes on both of these prompts to create the files.
Step 4: At this point, you should be looking at a new window that says “New Device Detected.” Leave the first radio button checked ā the one that says “Search automatically for settings” ā along with the checkbox that says “Search the Internet” and click “Next” at the bottom of the window. Finally, click Finish at the bottom of the next window to import the settings. If the program displays a green box on the tab for the controller you have selected, then you can continue to step 5. If it displays a red box on the tab, then see the troubleshooting section below.
If you’re using two gamepads, repeat this step for the second one.
Step 5: Click Save at the bottom-right corner of the window and close the program.
Step 6: Go to your Left 4 Dead bin directory, which will be something like C:\Program Files (x86)\Steam\steamapps\common\left 4 dead\bin. Rename the xinput1_3.dll file to xinput1_3.dll.old.
Step 7: Launch the game. Click on Options, then on Keyboard/Mouse. Make sure “Allow Developer Console” and “Gamepad” are both enabled. Then click Done.
Step 8: Hit the tilde key (~) on your keyboard to open the console and type:
ss_map mapname
Replace mapname with the actual name of a map. Auto-completion in the console should help you out here.
That’s it! You’re done. Unless you are playing Left 4 Dead 2. In that case, enter this command in the console once the map has finished loading:
connect_splitscreen localhost 2
When you’re done using a controller and want to use your keyboard/mouse again, go back into Options, Keyboard/Mouse, and disable the gamepad.
Have fun!
What if x360ce doesn’t recognize my gamepad?
Since I normally use a fairly ubiquitous gamepad (Logitech Wireless Gamepad F710), I had never encountered this problem until I tried my other one (PS3 Afterglow Controller by PDP). If x360ce doesn’t recognize your gamepad, it will display a red box on the tab for that controller and the controller diagram will be all grayed out:

Go to the Settings Database tab on the top row of tabs. Under Controller/Device, select the gamepad that’s having problems. Then click on the Global Settings tab to get a list of available configurations from the internet:

I have my list sorted by the Users column. I think that, by default, x360ce will use the highest ranked configuration for your gamepad settings. In my case, it was using the top one in the list, with 5C1EA9F1 under SID and 11 Users. To use a different configuration, double click on another entry in the list. Then click Yes to import the settings. A couple of seconds after that, if you picked the right one, the red box on the controller tab should change to a green box:

At this point, you should be able to push the buttons on your controller and see the corresponding buttons light up in the diagram on the controller tab. This will tell you for sure if your gamepad settings are working. Do the same for the joysticks to make sure those are working too.
If everything checks out, then you can resume from step 5 above.
I put way too much work into this not to share it:
This is how it started:

An adorable cat with bad taste. (via)
After some color correction (which I am not very good at), I began to replace the Apple logo with Tux the Penguin:

Vectorized Tux. (via)
He doesn’t glow very well, but Inverted Tux should!
I added Inveted Tux as a layer to my cat image and placed a solid black layer below. Then I skewed the two layers together to approximate the correct perspective:

Photoshop trickery.
Finally, I removed the solid black layer and blurred Tux a little bit.
Recently, I needed to view my website on an iPad in a test environment. My test server is on an internal network, which is impossible to view without write access to a hosts file.
I’m glad to say that I finally managed to bend the iPad to my will, and – although it feels like it may have gotten the best of me – my sanity is mostly intact. Since I am such a generous person, I will spare you from hours of frustration and tell you how to edit the hosts file in iOS. Just follow these instructions, and everything will be okay.
First of all, if you haven’t jailbroken your device, you will need to do that first.
Notice: I do not recommend jailbreaking your device!!!
With that mandatory disclaimer out of the way, if you have to do it, I suggest upgrading (or downgrading, if you made the mistake of upgrading to iOS 6) to iOS 5.1.1 and using Absinthe 2.0.4 to jailbreak. (See here for a tutorial.) The folks at Chronic Dev Team and iPhone Dev Team have done a great job at making it a mostly painless process. (If you want to jailbreak a different version of iOS, then… well, good luck to you.)
EDIT 4/15/2013: Shortly after I wrote this, a tool called Evasi0n made it possible to jailbreak any version of iOS up to and including 6.1.2, but not 6.1.3. (See here.)
Once that’s done, open Cydia (which will appear on the springboard) and download iFile. You can spend a few bucks to get the full-featured version, but you don’t need to for what we’re doing.
Next, launch iFile and navigate to the root (/) directory. Tap on the hosts file, and select the option to open it with Text Viewer. From here, you should be able to edit and save the file.
This is all pretty standard stuff to anyone with Unix experience. However, there is one thing about the hosts file in iOS that tripped me up for HOURS:
Make sure you leave a blank line at the end of the hosts file!
For whatever reason, the operating system simply refuses to read the last line of the hosts file. Anything you put there will be IGNORED.
That’s it. Have fun! And please let me know if you find a decent five row keyboard in Cydia. I literally cannot function in a terminal without ARROW KEYS.
It wouldn’t surprise me if nobody noticed, but I overhauled my NHibernate articles. They are now grouped together in one convenient location.
Maybe when I have time, I will write about all the things I was doing wrong and how I fixed them.