如何使用c++;win32 Api? 我使用C++ Win32 API .< /P>

如何使用c++;win32 Api? 我使用C++ Win32 API .< /P>,c++,windows,winapi,C++,Windows,Winapi,我想使用分隔符拆分字符 这个字符像“CN=USERS,OU=Marketing,DC=RAM,DC=COM” 我想在第一个逗号(,)后将字符拆分为。这意味着我只需要 OU=Marketing,DC=RAM,DC=COM. 我已经尝试了strtok的function,但它只拆分CN=用户 如何实现这一点?尝试下面的代码,您应该能够轻松获取每个项目(以“,”分隔): strtok版本: char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";

我想使用分隔符拆分字符

这个字符像“CN=USERS,OU=Marketing,DC=RAM,DC=COM”

我想在第一个逗号(,)后将字符拆分为。这意味着我只需要

OU=Marketing,DC=RAM,DC=COM.

我已经尝试了strtok的
function,但它只拆分CN=用户


如何实现这一点?

尝试下面的代码,您应该能够轻松获取每个项目(以“,”分隔): strtok版本:

char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
  char *token = std::strtok(domain, ",");
  while (token != NULL) {
      std::cout << token << '\n';
      token = std::strtok(NULL, ",");
  }
chardomain[]=“CN=USERS,OU=Marketing,DC=RAM,DC=COM”;
char*token=std::strtok(域“,”);
while(令牌!=NULL){

std::cout尝试下面的代码,您应该能够轻松地获取每个项目(以“,”分隔): strtok版本:

char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
  char *token = std::strtok(domain, ",");
  while (token != NULL) {
      std::cout << token << '\n';
      token = std::strtok(NULL, ",");
  }
chardomain[]=“CN=USERS,OU=Marketing,DC=RAM,DC=COM”;
char*token=std::strtok(域“,”);
while(令牌!=NULL){

std::cout使用
strchr
使它变得非常简单:

char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
char *p = strchr(domain, ',');
if (p == NULL)
{
    // error, no comma in the string
}
++p; // point to the character after the comma

使用
strchr
非常容易:

char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
char *p = strchr(domain, ',');
if (p == NULL)
{
    // error, no comma in the string
}
++p; // point to the character after the comma

看看这个:你为什么需要Win32 api呢?@Sidharth@chris:我不能用string,Std::substring这样的,只有我可以用windows函数,就是这样,你能给出任何其他建议吗。用
strchr
找到第一个逗号。然后你可以在那个位置点一个
char*
,这就是你的字符串。看看这个:为什么你需要Win32 api吗?@Sidharth@chris:我不能像那样使用字符串,Std::substring,只有我可以使用windows函数,这是y,你能给出任何其他建议吗。使用
strchr
找到第一个逗号。然后你可以在那个位置指向一个
char*
,这是你的字符串。@billz:谢谢你的回复,但我不能使用Std::stringstream等。你可以给其他windows函数,如strtok、strcmp等@sanju:strtok、strcmp不是windows函数。它是标准CRT(C运行时库)的一部分@billz:谢谢你的回复,但我不能使用std::stringstream等。你能给其他的windows函数比如strtok、strcmp等吗@sanju:strtok、strcmp不是windows函数。它是标准CRT(C运行时库)的一部分