You're exactly 180 degrees from being correct. The projectiles fired by modern tanks' main guns are next to useless against dismounted infantry, as they are designed specifically to penetrate opposing armor. Fired against a group of charging soldiers you'd be lucky to get 3-4 kills per shot.
Besides which, modern infantry doesn't charge a tank, they set up an ambush with proper cover and concealment, wait for the tank to roll into range, and then pop it with an anti-tank missile (or in WWII, a bazooka). Dismounted infantry are the bane of tank formations, which is why modern armies mix infantry companies into the tank battalions (and vice versa); tanks kill other tanks and vehicles, infantry kills tanks, and artillery kills infantry.
Let me point out that there are variety of shells that a tank carries into combat. It isn't like in the video game where a tank only fires a certain type of shell, which most likely is either a HEAT or AP(FS)DS, but it carries anti-infantry rounds as well. Its also used for providing coverfire (or actually being a cover) for infantry advancing, which would translate to ranged combat (though, judging from some odd ranged combat logics in civs where machinegun shoots shorter range than a bow...).
As you have mentioned, infantry are relying on ambush and set up fortification to fight against a tank. Former is usually done in close quarter situation, while the latter is obvious to the tanks so tanks would just use their natural ability to 'remove' the fortification from afar. Most armies do not let the tank go into combat without infantry support because of the ambush situation, especially when the close quarter combat is expected. And its not like tank cannot overwhelm infantry even in close quarters, when it comes to modern tanks. Usually the only downfall of tanks in modern close quarters (aka urban environment) is because most armies try to avoid too much damage to the city. If they don't care, they probably would not even send in tanks or infantry. They would just air / artillery strike it until it is no more (have no idea why we can't raze enemy cities this way in civ. LoL).
Infantry is not relied upon to kill tanks. Tanks are supposed to kill tanks, and everything else when situation grants. Infantry are used to taking over key location and protecting the previously mentioned tank, and are given anti-tank weapons to protect infantry division in close proximity, not for going offensive against other tanks (and waiting for the tank to get closer is taking risks as well, as there is higher chance in that tank might just blast the said infantry position from miles away).
Infantry fights in environments where tanks are not going to be much use, like in jungle, but we have evidence (through WWII and Vietnam) that tanks can still perform relatively well. Its just that infantry is better suited for non-open terrain combat when compared to tanks.
As the tank in the game is designed as a melee unit, the actual logic in using tanks to gain a lockdown on a key location very fast and deterring enemies from approaching the said location against slower paced enemies from afar, is removed along with the fact that infantries should be providing barrier between the tank and approaching enemy infantry in close quarters situation. The only thing that the game sort of lets players/AIs to do is to use tanks as cover for infantries (which is a one of actual uses of tanks), but thats pretty much it, when it comes to infantry / tank combo tactics.