Cast on several sts more than for the gauge listed in the pattern. If it says 19sts = 4", then use at least 25 sts. This is because the edge sts aren't quite the same size as the ones in the center of a row and tend to curl under, so you shouldn't use them when measuring. After you've knit several inches, you can bind off your piece and measure 4" over the middle sts, and it helps to measure in a couple different places. It may also be a good idea to wash and block the swatch like you will the final item because some yarns shrink up or relax a lot and the gauge changes. So it's good to write down the measurements both before and after.
Now, this is for an item that needs to fit a certain size like a hat, gloves/mittens, socks or a sweater. For a scarf or blanket it's not quite so important to take the time to do this, the item will be slightly smaller or larger and may not make a difference. For a scarf you can just cast on and knit a few inches, then measure it to see if it's close to the gauge and the width you need.