Using printf
you can do
printf("Here are the first 8 chars: %.8s\n", "A string that is more than 8 chars");
If you're using C++, you can achieve the same result using the STL:
using namespace std; // for clarity
string s("A string that is more than 8 chars");
cout << "Here are the first 8 chars: ";
copy(s.begin(), s.begin() + 8, ostream_iterator<char>(cout));
cout << endl;
Or, less efficiently:
cout << "Here are the first 8 chars: " <<
string(s.begin(), s.begin() + 8) << endl;