Reputation: 402
#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'
Upvotes: 6
Views: 26984
Reputation: 18751
string::front
was introduced in c++11. On a mac make sure you are using clang, because g++ is not as updated on osx, and use the command line options clang++ -std=c++11 your_program.cpp
. You may also need to use the option -stdlib=libc++
Upvotes: 5
Reputation: 23644
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.
Upvotes: 11