-7

How can I check if the first element of an vector is a quote ?

For exemple:

vector<string> atom;

How can I check if atom[k][0] got an quote on the first position in C++?

Thank you

Scusf0
  • 323
  • 1
  • 3
  • 14

1 Answers1

1

You can use

if( atom[k][0] == '\"' )

Exception handled version (.at() throws an error if index is out of bounds):

if( atom[k].at(0) == '\"' )
nipunasudha
  • 2,427
  • 2
  • 21
  • 46
  • 3
    You should specify that this will throw if the string is empty, which may or may not be what the OP wants. And if the string is guaranteed not to be empty, `.at()` is a waste of cycles. As written, the OP wants `[k][0]`, so I don't know why you switched to `.at()`, especially without explaining that. – underscore_d Nov 08 '17 at 09:29
  • Can you explain why the down-voting? Is answering correctly to a weak question a bad thing? – nipunasudha Nov 08 '17 at 10:57