本文整理汇总了C++中word::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ word::c_str方法的具体用法?C++ word::c_str怎么用?C++ word::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类word
的用法示例。
在下文中一共展示了word::c_str方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forAll
void Foam::hdf5SurfaceWriter::writeData
(
const hid_t& file_id,
const word& surfaceName,
const word& fieldName,
const word& time,
const Field<scalar>& values
)
{
ioScalar* scalarData;
scalarData = new ioScalar[values.size()];
// Loop through the field and construct the array
forAll(values, iter)
{
scalarData[iter] = values[iter];
}
hid_t group = H5Gopen2(file_id, time.c_str(), H5P_DEFAULT);
hsize_t dimsf[1];
dimsf[0] = values.size();
hid_t dataspace = H5Screate_simple(1, dimsf, NULL);
hid_t datatype = H5Tcopy(H5T_SCALAR);
char datasetName[80];
sprintf
(
datasetName,
"%s/%s",
time.c_str(),
fieldName.c_str()
);
hid_t dataset = H5Dcreate2(file_id, datasetName, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dataset, H5T_SCALAR, H5S_ALL,
H5S_ALL, H5P_DEFAULT, scalarData);
H5Dclose(dataset);
H5Sclose(dataspace);
H5Tclose(datatype);
H5Gclose(group);
delete [] scalarData;
}
示例2: home
Foam::fileName Foam::home(const word& userName)
{
struct passwd* pw;
if (userName.size())
{
pw = getpwnam(userName.c_str());
}
else
{
char* env = getenv("HOME");
if (env != NULL)
{
return fileName(env);
}
pw = getpwuid(getuid());
}
if (pw != NULL)
{
return pw->pw_dir;
}
else
{
return fileName::null;
}
}
示例3: env
bool env(const word& envName)
{
const DWORD actualBufferSize =
::GetEnvironmentVariable(envName.c_str(), NULL, 0);
const bool envExists = (0 < actualBufferSize);
return envExists;
}
示例4: setenv
bool Foam::setEnv
(
const word& envName,
const string& value,
const bool overwrite
)
{
return setenv(envName.c_str(), value.c_str(), overwrite) == 0;
}
示例5: getEnv
string getEnv(const word& envName)
{
std::string envAsString;
const DWORD actualBufferSize =
::GetEnvironmentVariable(envName.c_str(), NULL, 0);
if (0 < actualBufferSize)
{
MSwindows::AutoArray<TCHAR> actualBuffer(actualBufferSize);
::GetEnvironmentVariable(envName.c_str(),
actualBuffer.get(),
actualBufferSize);
envAsString = actualBuffer.get();
toUnixPath(envAsString);
}
return envAsString;
}
示例6:
bool setEnv
(
const word& envName,
const string& value,
const bool overwrite
)
{
const bool success =
::SetEnvironmentVariable(envName.c_str(), value.c_str());
return success;
}
示例7: getEnv
Foam::string Foam::getEnv(const word& envName)
{
char* env = getenv(envName.c_str());
if (env)
{
return string(env);
}
else
{
// Return null-constructed string rather than string::null
// to avoid cyclic dependencies in the construction of globals
return string();
}
}
示例8: mfIter
bool Foam::functionEntry::execute
(
const word& functionName,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
is.fatalCheck
(
"functionEntry::execute"
"(const word&, const dictionary&, primitiveEntry&, Istream&)"
);
if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
{
cerr<<"functionEntry::execute"
<< "(const word&, const dictionary&, primitiveEntry&, Istream&)"
<< " not yet initialized, function = "
<< functionName.c_str() << std::endl;
// return true to keep reading anyhow
return true;
}
executeprimitiveEntryIstreamMemberFunctionTable::iterator mfIter =
executeprimitiveEntryIstreamMemberFunctionTablePtr_->find(functionName);
if (mfIter == executeprimitiveEntryIstreamMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"functionEntry::execute"
"(const word&, const dictionary&, primitiveEntry&, Istream&)"
) << "Unknown functionEntry '" << functionName
<< "' in " << is.name() << " near line " << is.lineNumber()
<< endl << endl
<< "Valid functionEntries are :" << endl
<< executeprimitiveEntryIstreamMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
return mfIter()(parentDict, entry, is);
}
示例9: myTimer
bool Foam::ping
(
const word& destName,
const label destPort,
const label timeOut
)
{
char *serverAddress;
struct in_addr *ptr;
struct hostent *hostPtr;
volatile int sockfd;
struct sockaddr_in destAddr; // will hold the destination addr
u_int addr;
if ((hostPtr = gethostbyname(destName.c_str())) == NULL)
{
FatalErrorIn
(
"Foam::ping(const word&, const label)"
) << "gethostbyname error " << h_errno << " for host " << destName
<< abort(FatalError);
}
// Get first of the SLL of addresses
serverAddress = *(hostPtr->h_addr_list);
ptr = reinterpret_cast<struct in_addr*>(serverAddress);
addr = ptr->s_addr;
// Allocate socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
FatalErrorIn
(
"Foam::ping(const word&, const label)"
) << "socket error"
<< abort(FatalError);
}
// Fill sockaddr_in structure with dest address and port
memset (reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr));
destAddr.sin_family = AF_INET;
destAddr.sin_port = htons(ushort(destPort));
destAddr.sin_addr.s_addr = addr;
timer myTimer(timeOut);
if (timedOut(myTimer))
{
// Setjmp from timer jumps back to here
fdClose(sockfd);
return false;
}
if
(
connect
(
sockfd,
reinterpret_cast<struct sockaddr*>(&destAddr),
sizeof(struct sockaddr)
) != 0
)
{
// Connection refused. Check if network was actually used or not.
int connectErr = errno;
fdClose(sockfd);
if (connectErr == ECONNREFUSED)
{
return true;
}
//perror("connect");
return false;
}
fdClose(sockfd);
return true;
}
示例10: env
bool Foam::env(const word& envName)
{
return getenv(envName.c_str()) != NULL;
}
示例11: add
void LuaFoamDictionaryParserDriver::add(const word& name,const string &value)
{
lua_pushstring(lua(),value.c_str());
lua_setfield(lua(),-2,name.c_str());
}
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-swak4Foam-dev,代码行数:5,代码来源:LuaFoamDictionaryParserDriver.C
示例12:
Foam::instant::instant(const word& tname)
:
value_(atof(tname.c_str())),
name_(tname)
{}
示例13: main
int main(int argc, char *argv[])
{
timeSelector::addOptions();
# include "addRegionOption.H"
argList::validArgs.append("patchName");
argList::validArgs.append("firstPatchNumber");
argList::validArgs.append("lastPatchNumber");
# include "setRootCase.H"
# include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
# include "createNamedMesh.H"
word patchName = args[1];
const word charfirstPatchNumber = args[2];
const word charlastPatchNumber = args[3];
char* pEnd;
int firstPatchNumber = strtod(charfirstPatchNumber.c_str(), &pEnd);
int lastPatchNumber = strtod(charlastPatchNumber.c_str(), &pEnd);
Info << "Patch name: " << patchName << " id = ["<< charfirstPatchNumber <<":"<< charlastPatchNumber <<"]" << endl;
Info << " " << endl;
OFstream* outputFile;
fileName outpuFilename(mesh.time().path()/"wettedAreaPatch"+patchName+charfirstPatchNumber+"-"+charlastPatchNumber);
outputFile = new OFstream(outpuFilename);
*outputFile << "#Time " << tab << "totalWettedArea" << tab;
for(label id=firstPatchNumber; id<=lastPatchNumber; id++)
{
*outputFile << "wettedArea-" << id << tab;
}
*outputFile << endl;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
mesh.readUpdate();
// Read gas density
IOobject alphaheader
(
"alpha.water",
runTime.timeName(),
mesh,
IOobject::MUST_READ
);
Info<< " Reading alpha" << endl;
volScalarField alpha(alphaheader,mesh);
scalar totalWettedArea(0);
scalarField wettedArea(lastPatchNumber+1,scalar(0));
scalar totalSurfaceArea(0);
for(label id=firstPatchNumber; id<=lastPatchNumber; id++)
{
// Calculate wetted area on the plane
word patchNumber;
std::stringstream ss;
ss << id;
patchNumber = ss.str();
const label patchI = mesh.boundaryMesh().findPatchID(patchName+patchNumber);
if (patchI < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
<< exit(FatalError);
}
wettedArea[id] = gSum(alpha.boundaryField()[patchI]*mesh.magSf().boundaryField()[patchI]);
totalWettedArea += wettedArea[id];
totalSurfaceArea += gSum(mesh.magSf().boundaryField()[patchI]);
}
if(Pstream::master()) //Write only if master
{
Info<< " Writing mass flow rates into the file " << outpuFilename << endl;
*outputFile << alpha.mesh().time().value() << tab
<< totalWettedArea << tab;
for(label id=firstPatchNumber; id<=lastPatchNumber; id++)
{
*outputFile << wettedArea[id] << tab << " ";
}
*outputFile << totalSurfaceArea << endl;
}
Info << " " << endl;
}