Mark P said:
Gary Wessle wrote:
Hi
is there a method "split or something" to do this
string s = "abcdef"
string s1 = split(s,0,2) // gives abc
string s2 = split(s,3,5) // gives def
or I have to write something up?
thanks
string::substr
or, look at the generalized copy ctor which takes range paramters
not sure why it will only work if I uncomment the "using namespace
std;"
but will not work this way below
#include <iostream>
#include <string>
using std::substr;
using std::cout;
//using namespace std;
int main() {
string s = "abcdef";
cout << s.substr(0,3) << '\n';
}
******** error ****************
g++ -c -o try.o try.cpp
try.cpp:3: error: 'std::substr' has not been declared
try.cpp: In function 'int main()':
try.cpp:10: error: 'string' was not declared in this scope
try.cpp:10: error: expected `;' before 's'
try.cpp:12: error: 's' was not declared in this scope
make: *** [try.o] Error 1
abc