#include <iostream>
#include <string>
#include <sstream>
std::istream& get_line_strip_comments( std::istream& stm, std::string& str )
{
if( std::getline( stm, str ) )
{
auto pos = str.find( "//" ) ;
if( pos == 0 ) return get_line_strip_comments( stm, str ) ;
else if( pos != std::string::npos ) str.erase(pos) ;
}
return stm ;
}
int main()
{
std::istringstream stm( R"(
this is a line with no comments
// this is a comment line
some text // and then a comment
more text / / this is not a comment // but this is\n)" ) ;
std::string str ;
while( get_line_strip_comments( stm, str ) ) std::cout << str << '\n' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KCnN0ZDo6aXN0cmVhbSYgZ2V0X2xpbmVfc3RyaXBfY29tbWVudHMoIHN0ZDo6aXN0cmVhbSYgc3RtLCBzdGQ6OnN0cmluZyYgc3RyICkKewogICAgaWYoIHN0ZDo6Z2V0bGluZSggc3RtLCBzdHIgKSApCiAgICB7CiAgICAgICAgYXV0byBwb3MgPSBzdHIuZmluZCggIi8vIiApIDsKICAgICAgICBpZiggcG9zID09IDAgKSByZXR1cm4gZ2V0X2xpbmVfc3RyaXBfY29tbWVudHMoIHN0bSwgc3RyICkgOwogICAgICAgIGVsc2UgaWYoIHBvcyAhPSBzdGQ6OnN0cmluZzo6bnBvcyApIHN0ci5lcmFzZShwb3MpIDsKICAgIH0KICAgIHJldHVybiBzdG0gOwp9CgoKaW50IG1haW4oKQp7CiAgICBzdGQ6OmlzdHJpbmdzdHJlYW0gc3RtKCBSIigKdGhpcyBpcyBhIGxpbmUgd2l0aCBubyBjb21tZW50cwovLyB0aGlzIGlzIGEgY29tbWVudCBsaW5lCnNvbWUgdGV4dCAvLyBhbmQgdGhlbiBhIGNvbW1lbnQKbW9yZSB0ZXh0IC8gLyB0aGlzIGlzIG5vdCBhIGNvbW1lbnQgLy8gYnV0IHRoaXMgaXNcbikiICkgOwoKICAgIHN0ZDo6c3RyaW5nIHN0ciA7CiAgICB3aGlsZSggZ2V0X2xpbmVfc3RyaXBfY29tbWVudHMoIHN0bSwgc3RyICkgKSBzdGQ6OmNvdXQgPDwgc3RyIDw8ICdcbicgOwp9Cg==