- At compile time, are there any differences regarding build performance?
- When the program is run, what are the differences?
Emanuel Gauler's questions
I have the following lines:
using par = std::pair<std::string, unsigned>;
std::istream& operator>>( std::istream&is, par & p ) {
is >> p.first >> p.second;
return is;
}
std::ostringstream out( "qwe 123\nasd 234", std::ios::out | std::ios::in );
std::istream in( out.rdbuf() );
std::copy( std::istream_iterator<par>( in ), std::istream_iterator<par>(),
std::ostream_iterator<par>( std::cout, "\t" ) );
And it doesn't work for me. What is the problem with this algorithm? I leave a link to a web editor and compiler. link to example
I need to capture the words that go into
int main( int argc, char**argv )
and pass it to a std::wstring
What function exists in the c++11 standard?
I am looking for a way to count the characters of a word, phrase or text in Spanish.
For example:
cout << "Cantidad de letras: " << letters_counted( "¿Hola, cómo estás?" ) << endl;
The result should be:
Cantidad de letras: 13
I am not finding a way to compare letters with accents, is there a way?
This is an attempt that failed me:
int count=0; txt="Hola, cómo estás";
regex rx( "[a-zA-ZñÑáéíóúÁÉÍÓÚ]" );
for( sregex_iterator it( txt.cbegin(), txt.cend(), rx ); it!=sregex_iterator();
++it ) count++;
cout << count << endl;
Instead of displaying 13, which is the number of letters, it returns 15.
I don't understand how to treat extended characters, like vowels with accents, á, é, í, ó, ú and ñ .
This is another try, the algorithm is similar to @AngelAngel.
int letters_counted_in_text( std::string const&text ) {
count = 0
string abc = "abcdefghijklmnñopqrstuvwxyzáéíóú"
"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ";
for( unsigned i=0; i<text.length(); ++i )
for( unsigned j=0; j<abc.length(); ++j )
if( text.at( i )==abc.at( j ) )
{
count++;
j=abc.length();
}
return count;
}
But it also returns 15 letters when it should be 13, like " Hello, how are you ".
Is there possibility to use u16string or wstring? To treat the letters of the Spanish alphabet.