本文整理汇总了C++中t_string::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ t_string::c_str方法的具体用法?C++ t_string::c_str怎么用?C++ t_string::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类t_string
的用法示例。
在下文中一共展示了t_string::c_str方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LookupHost
int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType )
{
#if defined( HTM_NOSOCKET2 )
return 0;
#else
// Lose old info
Destroy();
// Ensure we have a valid pointer
if ( !x_sServer.length() )
return 0;
// First try to interpret as dot address
unsigned long uAddr = inet_addr( x_sServer.c_str() );
if ( INADDR_NONE == uAddr )
{
LPHOSTENT pHe = gethostbyname( x_sServer.c_str() );
if ( !pHe )
return 0;
LPIN_ADDR pia = (LPIN_ADDR)*pHe->h_addr_list;
if ( !pia )
return 0;
// Grab the address
uAddr = *(DWORD*)&pia->S_un.S_addr;
} // end if
SetRawAddress( ntohl( uAddr ), x_uPort, x_uType );
return 1;
#endif
}
示例2: CreateDirectory
bool DirUtil::CreateDirectory( const t_string &dirPath )
{
if (!CreateParentDirectory(dirPath))
{
return false;
}
return ::CreateDirectory(dirPath.c_str(), NULL) == TRUE;
}
示例3: DeleteDirectory
bool DirUtil::DeleteDirectory( const t_string &path )
{
#if 0
SHFILEOPSTRUCT FileOp;
ZeroMemory((void*)&FileOp, sizeof(SHFILEOPSTRUCT));
t_string strFromPath = MakePathRegular(path);
// this string must be double-null terminated
strFromPath.append(1, _T('\0'));
FileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = strFromPath.c_str();
FileOp.pTo = NULL;
FileOp.wFunc = FO_DELETE;
return SHFileOperation(&FileOp) == 0;
#endif
bool ret = true;
std::vector<t_string> fileList;
std::vector<t_string> dirList;
if (EnumFiles(path, fileList))
{
for (size_t i = 0; i < fileList.size(); i++)
{
if (!DeleteFileIfExist(fileList.at(i)))
{
ret = false;
break;
}
}
}
if (!ret)
{
return false;
}
if (EnumDirs(path, dirList))
{
for (size_t i = 0; i < dirList.size(); i++)
{
if (!DeleteDirectory(dirList.at(i)))
{
ret = false;
break;
}
}
}
if (!ret)
{
return false;
}
return ::RemoveDirectory(path.c_str()) ? true : false;
}
示例4: DeleteFileIfExist
bool DirUtil::DeleteFileIfExist( const t_string &filePath )
{
if (IsFileExist(filePath))
{
if (!::DeleteFile(filePath.c_str()))
{
_tchmod(filePath.c_str(), 0777);
return ::DeleteFile(filePath.c_str()) ? true : false;
}
else
{
return true;
}
}
else
{
return false;
}
}
示例5: SetDotAddress
// +++ Make IPv6 safe
int CIpAddress::SetDotAddress( const t_string &x_sDotAddress, unsigned int x_uPort, unsigned int x_uType )
{
if ( !x_sDotAddress.length() )
return 0;
// Convert the dot address
u_long ip = ntohl( inet_addr( x_sDotAddress.c_str() ) );
if ( INADDR_NONE == ip )
return 0;
SetRawAddress( ip, x_uPort, x_uType );
return 1;
}
示例6: Write
DWORD Client::Write(t_string write_buffer)
{
if (eState_ != STATE::started)
{
return ERROR_NOT_FOUND;
}
DWORD cbWritten;
EnterCriticalSection(&csPipe_Write_);
BOOL bSuccess = WriteFile (
hPipe_, // pipe handle
write_buffer.c_str(), // message
write_buffer.length() *
sizeof(t_string::traits_type::char_type), // message length
&cbWritten, // bytes written
NULL // not overlapped
);
LeaveCriticalSection(&csPipe_Write_);
return bSuccess ? ERROR_SUCCESS : GetLastError();
}
示例7: Write
DWORD Base::Write(const t_string & write_buffer, HANDLE pipe_handle, CRITICAL_SECTION & write_critical_section)
{
if (eState_ != STATE::started)
{
return ERROR_NOT_FOUND;
}
EnterCriticalSection(&write_critical_section);
DWORD cbWritten;
BOOL bSuccess = WriteFile (
pipe_handle, // pipe handle
write_buffer.c_str(), // message
write_buffer.length() *
sizeof(t_string::traits_type::char_type), // message length
&cbWritten, // bytes written
NULL // not overlapped
);
LeaveCriticalSection(&write_critical_section);
return bSuccess ? ERROR_SUCCESS : GetLastError();
}
示例8: LookupHost
int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType )
{
// Lose old info
Destroy();
// Ensure we have a valid pointer
if ( !x_sServer.length() )
return 0;
// +++ Get this working eventually
// #if !defined( HTM_USE_GETHOSTBYNAME )
#if 0
in_addr ip4;
if ( inet_pton( PF_INET, x_sServer.c_str(), &ip4 ) )
{ SetRawAddress( ntohl( *(unsigned long*)&ip4.s_addr ), x_uPort, x_uType );
return 1;
} // end if
struct addrinfo hints, *addr = 0;
memset( &hints, 0, sizeof( hints ) );
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
int rval = 0;
if ( rval = getaddrinfo( x_sServer.c_str(), 0, &hints, &addr ) )
return 0;
int max = 128;
while ( !addr && max-- )
{
switch( addr->ai_family )
{
case AF_INET :
{
sockaddr_in *psai = (sockaddr_in*)addr->ai_addr;
in_addr *pia = &psai->sin_addr;
SetRawAddress( ntohl( *(unsigned long*)&pia->s_addr ), x_uPort, x_uType );
return 1;
} break;
case AF_INET6 :
{
// +++ Add v6 support
sockaddr_in6 *psai = (sockaddr_in6*)addr->ai_addr;
sin6_addr *pia6 = &psai->sin6_addr;
} break;
} // end switch
if ( addr == addr->ai_next )
addr = 0;
else
addr = addr->ai_next;
} // end while
return 0;
#else
// First try to interpret as dot address
unsigned int uAddr = inet_addr( x_sServer.c_str() );
if ( INADDR_NONE != uAddr )
{ SetRawAddress( ntohl( uAddr ), x_uPort, x_uType );
return 1;
} // end if
struct hostent *pHe;
do { pHe = gethostbyname( x_sServer.c_str() );
} while ( !pHe && EINTR == h_errno );
if ( !pHe || !pHe->h_addr_list )
return 0;
in_addr *pia = (in_addr*)*pHe->h_addr_list;
if ( !pia )
return 0;
SetRawAddress( ntohl( *(unsigned int*)&pia->s_addr ), x_uPort, x_uType );
return 1;
#endif
}