James Comey. Gary Cameron/Reuters President-elect Donald Trump met with former CIA Director David Petraeus on Monday to reportedly discuss being secretary of state.

"Just met with General Petraeus — was very impressed!" Trump tweeted shortly after the meeting.

Much has been made of the fact Petraeus pleaded guilty in 2015 to a misdemeanor charge of mishandling classified information, and Trump has lambasted Democratic presidential nominee Hillary Clinton for doing what he claimed was worse while she was secretary of state.

In comparing both situations this summer — following his announcement that the FBI would not pursue charges against Clinton — FBI Director James Comey explained at a congressional hearing why the case involving Petraeus compromising classified information was different from the investigation into Clinton's use of a private email server.

The Petraeus case "illustrates importantly the distinction to this case," Comey said at the hearing, held by the House Oversight and Government Reform Committee.

During a press conference days before, Comey said the investigation yielded no evidence that Clinton deliberately attempted to mislead investigators. He added that even though he described Clinton as being "extremely careless" with sensitive information, her conduct did not meet the threshold used to prosecute past violators who shared classified information over unclassified channels.

Petraeus had disclosed classified information to his biographer.

Trump said shortly after Comey's announcement about the Clinton investigation that he believed Petraeus got in trouble for "far less."

"The system is rigged," Trump wrote on Twitter. "General Petraeus got in trouble for far less. Very very unfair! As usual, bad judgment."

Petraeus kept highly classified information in a set of notebooks at his private residence, Comey said. The notebooks contained identities of covert officers, war strategy, and discussions with the president, and Petraeus disclosed the information with his biographer, with whom he was also having an affair.

"The Petraeus case to my mind illustrates perfectly the kinds of cases the Department of Justice is willing to prosecute," Comey said. "Even there they prosecuted him for a misdemeanor."

Petraeus "not only shared [classified information] with someone who was not allowed to have it, but we found it in a search warrant under the insulation in his attic, and then he lied to us about it in the investigation," Comey said.

He said Petraeus obstructed justice and committed intentional misconduct and later admitted it was the wrong thing to do.

"You have a perfect illustration of the kind of cases that get prosecuted," he said.

Asked by Democratic Rep. Elijah Cummings of Maryland whether the Clinton investigation was more damning than Petraeus' case, Comey said, "No, it's the reverse."

"His conduct to me illustrates the category of behavior that marks the prosecutions that are actually brought," Comey said.