本文整理汇总了C++中str::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ str::c_str方法的具体用法?C++ str::c_str怎么用?C++ str::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_table
void print_table(str s, const Ptable& T) {
printf("%s", s.c_str()); printf("\n");
int l = T.size();
if (l==0) {
printf(" ! Empty table\n");
return;
}
int c = T[0].size();
for (int i=0; i<l; i++) {
if (T[i].size()!=c) {
printf(" ! Table has different number of columns depending to the lines\n");
return;
}
}
str s0(" ",10);
const char* space = s0.c_str();
printf("%s", space);
for (int j=0; j<c; j++) printf("%11d",j);
printf("\n");
for (int i=0; i<l; i++) {
printf("%4d",i);
for (int j=0; j<c; j++) printf("%11s",p2s(T[i][j]).c_str());
printf("\n");
}
printf("\n");
}
示例2: Connect
bool NetworkClient::Connect(const str& server_address, double timeout) {
ScopeLock lock(&lock_);
bool ok = !is_socket_connecting_;
if (!ok) {
log_.Warning("Already connecting (from some other thread?)...");
deb_assert(false);
}
SocketAddress target_address;
if (ok) {
ok = target_address.Resolve(server_address);
if (!ok) {
log_.Warningf("Could not resolve server address '%s'.", server_address.c_str());
}
}
if (ok) {
const std::string connection_id = SystemManager::GetRandomId();
is_socket_connecting_ = true;
lock.Release();
socket_ = mux_socket_->Connect(target_address, connection_id, timeout);
lock.Acquire();
is_socket_connecting_ = false;
ok = (socket_ != 0);
}
return (ok);
}
示例3: print_hist
void print_hist(str s, int i0, List hist, bool latex) {
str et = latex ? " & " : " | ";
str slash = latex ? "\\\\ \n" : "\n";
str rrr(10,'r');
if (latex) printf("\\begin{table}[H]\\begin{center} \n \\caption{%s (interval %d)} \n \\begin{tabular}{%s}\n",s.c_str(),i0,rrr.c_str());
else printf("%s (interval %d)\n",s.c_str(),i0);
int size = hist.size();
for (int i=0; i<size; i++) {
str s = ((i+1)%10==0 || i==size-1) ? slash : et;
printf("%4s %s",f(hist[i]).c_str(),s.c_str());
}
if (latex) printf("\\end{tabular}\\end{center}\\end{table} \n");
fl();
}
示例4: SetBehaviorTendency
void Personality::SetBehaviorTendency( const str &packageName , float tendency )
{
PackageTendency_t pEntry;
BehaviorPackageType_t *package;
PackageTendency_t *checkEntry;
for ( int i = 1 ; i <= PackageList.NumObjects() ; i++ )
{
package = PackageList.ObjectAt( i );
if ( !Q_stricmp( packageName.c_str() , package->packageName.c_str() ) )
{
// We have a match, let's check to make sure we're not doubling up
for ( int j = 1 ; j <= _PackageTendencies.NumObjects() ; j++ )
{
checkEntry = &_PackageTendencies.ObjectAt( j );
if ( checkEntry->packageIndex == i )
{
checkEntry->tendency = tendency;
return;
}
}
// We don't have a match, so lets add the package
pEntry.lastTendencyCheck = 0.0f;
pEntry.tendency = tendency;
pEntry.packageIndex = i;
_PackageTendencies.AddObject( pEntry );
return;
}
}
}
示例5: create_node
Reader xml_reader::create_node(const str& name)
{
TiXmlElement* node = node_->FirstChildElement(name.c_str());
if (node)
return Reader( new xml_reader(node, types_, options_) );
return Reader();
}
示例6: logV
void HydrogenLinAlgSolver::logV(str path) {
ofstream of(path.c_str());
of << 0 << '\t' << 0. << '\t' << '?' << '\t' << '?' << endl;
for (uint j = 0; j < this->N_step; ++j)
of << (j+1) << '\t' << this->r[j] << '\t' << real(this->V[j]) << '\t' << imag(this->V[j]) << endl;
of << (this->N_step + 2) << '\t' << (this->R_max) << '\t' << '?' << '\t' << '?' << endl;
of.close();
}
示例7: generateVariableAssign
int generateVariableAssign(str varName, str varVal){
if(DEBUG)printf("\tPrzypisuje zmiennej <%s> wartosc <%s>\n", varName.c_str(), varVal.c_str());
int varIndex=variableManager.getItemIndex(varName);
if(varIndex==-1){
int cVarIndex=constantManager.getItemIndex(varName);
if(cVarIndex==-1){ // jezeli nie istnieje ani stala ani zmienna
return 1;
}else{ // jezeli istnieje stala
return 2;
}
}
// istnieje indeks zmiennej
if(DEBUG)printf("Indeks zmiennej to %d\n", varIndex);
char temp[50];
sprintf(temp, "STORE %d", varIndex);
addCodeLine(temp);
return 0;
}
示例8: create_iterator
WriteIterator xml_writer::create_iterator(const str& name, schema* type)
{
if (name.empty())
return WriteIterator( new xml_write_iterator(node_, type, types_) );
TiXmlElement* node = new TiXmlElement(name.c_str());
node_->LinkEndChild( node );
return WriteIterator( new xml_write_iterator(node, type, types_) );
}
示例9: print_list
void print_list(str s, Slist L) {
printf("%s \n",s.c_str());
int n = L.size();
//if (n==0) { // doesn't want to be compiled... mystery
//printf(" ! Empty list\n");
//return;
//}
for (int i=0; i<n; i++) printf("%5d : %s \n",i,L[i].c_str());
printf("\n");
}
示例10: isNumber
/** POMOCNICZE */
int isNumber(str name){
const char* buf = name.c_str();
while(*buf){
if (!isdigit(*buf))
return 0;
else
++buf;
}
return 1;
}
示例11: UsingWeaponNamed
//
// Name: UsingWeaponNamed()
// Parameters: None
// Description: Checks if our _activeWeapon has the same name
//
bool CombatSubsystem::UsingWeaponNamed(const str& weaponName)
{
if (!_activeWeapon.weapon)
return false;
if (!Q_stricmp(_activeWeapon.weapon->getName().c_str(), weaponName.c_str()))
return true;
return false;
}
示例12: setPostureState
void PostureController::setPostureState( const str &postureState )
{
if ( !_postureStateMap )
return;
if ( act->deadflag )
return;
_currentPostureState = _postureStateMap->FindState( postureState.c_str() );
}
示例13: save
void save(vector<str> bytecode,str filename)
{
//сохранение байткода в файл
ofstream f;
f.open(filename.c_str());
for(unsigned long long int i=0;i<bytecode.size();i++)
{
f<<bytecode[i].c_str()<<" ";
}
f.close();
}
示例14: f
tuple<long, long, long> count_file(const str& fn, bool cb, bool cw, bool cl)
{
long total_bytes=0, total_words=0, total_lines=0;
fstream f(fn.c_str());
str line;
while(len(line=readline(f))){
total_lines++;
auto words=line.split();
total_words+=len(words);
total_bytes=f.tellg();
}
return _t(total_bytes,total_words,total_lines);
}
示例15: print_mult_Dtable_latex
void print_mult_Dtable_latex(str s, str ss, Dtable T, double multX) {
printf("# %s \n Output data in %s \n\n",s.c_str(),ss.c_str());
FILE* pFile;
pFile = fopen(ss.c_str(),"w");
if (!pFile) {
printf("File opening failed \n"); fl();
myexit(1);
}
fprintf(pFile,"x ");
for (int i=0; i<T.size(); i++) fprintf(pFile,"%d ",i);
fprintf(pFile,"\n");
int maxrow = max_row(T);
for (int j=0; j<maxrow; j++) {
fprintf(pFile,"%f ",j*multX);
for (int i=0; i<T.size(); i++) {
if (j<T[i].size()) fprintf(pFile,"%f ",T[i][j]);
else fprintf(pFile,"0 ");
}
fprintf(pFile,"\n");
}
fclose(pFile);
}