Why do we use a cylinder as a Gaussian surface for infinitely long charged wire? 
Why do we use a cylinder as a Gaussian surface for infinitely long charged wire and not some other shape like cube?
 A: As a matter of fact you can choose any arbitrary shape to be your gaussian surface, as long as the charges are inside it. But just because we can, should we? Gauss Law can be thought of geometric approach to coulombs law. We use the geometric symmetries of the charge distribution to make our problem simpler.
Remember, Gauss' Law has a dot product of E and dS. If you want, you can take a cube centered around the line charge, but then you have to integrate over all the angles of E and dS making it more cumbersome. You can reduce this effort, by cunningly choosing such a surface where the electric field is always parallel to dS or perpendicular to the surface. That way, you don't have to include any angle consideration as before.
So in conclusion, you can choose any gaussian surface. But carefully choosing one makes our life easy. That's all.
A: As mentioned by others, any Gaussian surface can be used. There are some rules of thumb that are helpful. If you have some element of your system that extends uniformly and infinitely in some direction, then you want your Gaussian surface to be uniform in that direction as well. This suggests you want a cylinder of some cross section. The math is easier if the tangents of the surface are at a constant angle relative to the vectors pointing radially outward from the wire. This suggests you want the tangent to be perpendicular to the radii, so a circular cross section. 
A: Gauss' theorem would apply to a cube or other shape. You can write
$$
\int {\bf E} \cdot d{\bf S} = \frac{Q}{\epsilon_0}
$$
where the surface has any shape you like. However, the next step is to do the integral. How can we evaluate ${\bf E} \cdot d{\bf S}$ if we don't even know the angle between $\bf E$ and $d{\bf S}$? Nor do we know how the size of $\bf E$ relates to its distance from the middle of the cube or whatever. This is where the cylinder comes into play. If we choose a cylinder centred on the line charge then we can argue from the rotational and translational symmmetry that $\bf E$ must be radially outwards at the curved surface, and also that the size of $\bf E$ will be the same everywhere around the curved surface. It is only because we can make such a claim that we can proceed to do the integral. This neat way to perform the integral wouldn't work for a some other shape of surface.
Of course, if you were treating a different problem then you would choose your surface to suit that problem.
By the way, it is also interesting to note that Gauss's law on its own does not tell you the whole solution here, because it cannot rule out that the field may also have a further contribution having zero divergence so not contributing to the flux integral. To be specific, it does not rule out there may be a non-zero component of $\bf E$ in the direction in loops around the line charge. To rule that out you must invoke some further information, which could be either Coulomb's law, or the third Maxwell equation which describes Faraday's law of induction. In the present case there is no changing magnetic flux and therefore the line integral of $\bf E$ around any loop is zero, which rules out the possibility of a further component to $\bf E$. If your professor has omitted to mention this further piece of reasoning then you may like to inquire about it!
