Visual studio substrings std::string().substr()


Hello All,

I'm trying to figure out how to get a substring to work with visual studio.
Is there a way to do it without having to create a template argument list?

Any input would be great!

Thanks,

V




1
2
3
4
 char method[10] = "poo    ";

  if (std::string(method).substr(0, 7) == "foo")
    return foo;


error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)



1
2
3
4
 char method[10] = "poo    ";

  if (std::basic_string(method).substr(0, 7) == "foo")
    return foo;



: error C2955: 'std::basic_string' : use of class template requires template argument list
http://cplusplus.com/reference/string/string/substr/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// string::substr
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str="We think in generalities, but we live in details.";
                             // quoting Alfred N. Whitehead
  string str2, str3;
  size_t pos;

  str2 = str.substr (12,12); // "generalities"

  pos = str.find("live");    // position of "live" in str
  str3 = str.substr (pos);   // get from "live" to the end

  cout << str2 << ' ' << str3 << endl;

  return 0;
}
generalities live in details.
Last edited on
Thanks blackcoder41,

I did see that. I will have to do some test to try and replicate it in my implementation.

Thanks,

V
Topic archived. No new replies allowed.