#include <string>
#include <algorithm>
#include <iostream>
int main()
{
string str;
string str1;
int h = 0;
cin >> str;
if (str.length() > 10)
{
str1 += str.front();
h = str.length() - 2;
string s = to_string(h);
str1 += s;
str1 += str.back();
cout << str1;
}
else cout << str;
return 0;
}
compiles in XCode, but doesn`t on codeforces.ru/
сan't compile program.cpp:
program.cpp: In function 'int main()':
program.cpp:23:21: error: 'std::string' has no member named 'front'
program.cpp:27:29: error: 'to_string' was not declared in this scope
program.cpp:32:21: error: 'std::string' has no member named 'back'
Starting with C++20, you can use the starts_with method. std::string s = "abcd"; if (s. starts_with("abc")) { ... }
std::string class in C++ C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. String class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.
There is no functionality difference between string and std::string because they're the same type.
string is in the std namespace. You have the following options: Write using namespace std; after the include and enable all the std names: then you can write only string on your program. Write using std::string after the include to enable std::string : then you can write only string on your program.
One thing is that string::front
and std::to_string
are introduced since C++11. You have to make sure that you are using a compiler that supports those new features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With