Check if a given string is a comment or not | C ++ program for the above approach ; Function to check if the given string is a comment or not ; If two continuous slashes precedes the comment ; Driver Code ; Given string ; Function call to check whether then given string is a comment or not
#include <bits/stdc++.h> NEW_LINE using namespace std ; void isComment ( string line ) { if ( line [ 0 ] == ' / ' && line [ 1 ] == ' / ' && line [ 2 ] != ' / ' ) { cout << " It ▁ is ▁ a ▁ single - line ▁ comment " ; return ; } if ( line [ line . size ( ) - 2 ] == ' * ' && line [ line . size ( ) - 1 ] == ' / ' && line [ 0 ] == ' / ' && line [ 1 ] == ' * ' ) { cout << " It ▁ is ▁ a ▁ multi - line ▁ comment " ; return ; } cout << " It ▁ is ▁ not ▁ a ▁ comment " ; } int main ( ) { string line = " GeeksForGeeks ▁ GeeksForGeeks " ; isComment ( line ) ; return 0 ; }