2011-04-19 181 views
0

我有以下字符串:如何从一串字符串中获取字符串?

"hw_core_detectionhook::Iocard const*" 

我得到的只有第一部分,即所有文字空间之前存在的,即我只需要"hw_core_detectionhook::Iocard"一部分。

+0

它是一个'的std :: string'或'字符*'? – kennytm 2011-04-19 12:59:03

+4

http://stackoverflow.com/questions/236129/how-to-split-a-string – reggie 2011-04-19 13:00:59

回答

2
s.substr(0,s.find_first_of(" ")); 
+0

谢谢,但上面的表达会提供我第二部分,即const * – balaji 2011-04-19 13:08:29

+0

我试过了,它似乎提供了第一部分:http://www.ideone.com/Q84m9。如果s.find_first_of是第一个参数 - 那么它会提供“const *”。 – maxim1000 2011-04-19 13:19:33

3
std::stringstream ss; 

ss << "hw_core_detectionhook::Iocard const*"; 

std::string s; 

ss >> s; 

std::cout << s; 

输出:

hw_core_detectionhook::Iocard 

参阅完整的在线演示:http://www.ideone.com/w9l1C

+0

我不知道stringstream会这样做。谢谢。 +1 – karlphillip 2011-04-19 13:02:16

相关问题