You can think like this...
I am assuming that u r applying the force on Cart B (doesnt matter much :D)
You are pulling cart B, and the tension in the string is opposing ur force...however, tension being an internal force of the string, simultaneously helps Cart A to accelerate.
Now if...