Representing the Queen at the Royal Military Academy at Sandhurst in Surrey, he said that the "defence of the realm" is the Government's top priority.
Mr Cameron watched from the royal dais as 226 officer cadets were commissioned in the Sovereign's Parade.
He inspected the troops, stopping to chat to several of the young men and women before addressing them.
Mr Cameron said: "In return for all you will give to your country, I want your country to have pride in you.
"As a Government we will do everything we can to support you, to look after your families and to rebuild the military covenant that is so important to our country. First and foremost that means supporting you.
"People expect us to do the right thing by you.Yes, there will be difficult decisions ahead but I will never forget that defence of the realm is the first duty of any government."
He spoke of his personal pride at attending the parade, witnessed by about 3,000 of the cadets' friends and relatives, including several heads of state.
Mr Cameron also urged the officer cadets to take pride in their careers.
He said: "I want you to be proud of the difference that you can make. The security of our nation, and that of our allies across the world, is at stake."
He added that withdrawing troops from Afghanistan now could provide the Taliban with a chance to attack the West.