本文整理匯總了C++中std::atoi方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::atoi方法的具體用法?C++ std::atoi怎麽用?C++ std::atoi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::atoi方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: main
int main(int argc, char * argv[]) {
int szx = 0, szy = 0, szz = 0; /* x, y, z sizes */
if (argc > 1) { /* single size specified */
szx = szy = szz = atoi(argv[1]);
}
if (argc > 2) { /* Two sizes specified */
szz = 0;
szy = atoi(argv[2]);
}
if (argc > 3) { /* Three sizes specified */
szz = atoi(argv[3]);
}
if (szx == 0) szx = 10;
if (szy == 0) szy = 10;
if (szz == 0) szz = 10;
DTArray write_testing(szx,szy,szz);
firstIndex ii; secondIndex jj; thirdIndex kk;
/* Initialize the array with "coordinates" */
write_testing = ii + 10*jj + 100*kk;
/* And test the written outputs */
write_array(write_testing,"dat_seq",0);
write_array(write_testing,"dat_seq",1);
write_reader(write_testing,"dat_seq",true);
/* Nonsequenced version */
write_array(write_testing,"dat_nsq");
write_reader(write_testing,"dat_nsq");
return 0;
}
示例2: main
int main(int argc, char* argv[])
{
CGAL::Timer timer;
// first param is dimension
// second param is number of points
int dimension = 4;
int n = 100;
int m = 100;
if (argc > 1 && std::string(argv[1])== std::string("-h")) {
std::cout<<"usage: "<<argv[0]<<" [dim] [#points] [max coords]\n";
return 1;
}
if (argc > 1) dimension = atoi(argv[1]);
if (argc > 2) n = atoi(argv[2]);
if (argc > 3) m = atoi(argv[2]);
Delaunay_d T(dimension);
std::list<Point_d> L;
random_points_in_range(n,dimension,-m,m,L);
timer.start();
int i=0;
std::list<Point_d>::iterator it;
for(it = L.begin(); it!=L.end(); ++it) {
T.insert(*it); i++;
if (i%10==0)
std::cout << i << " points inserted" << std::endl;
}
timer.stop();
std::cout << "used time for inserts " << timer.time() << std::endl;
std::cout << "entering check" << std::endl;
timer.reset();
timer.start();
T.is_valid();
timer.stop();
std::cout << "used time for sanity check " << timer.time() << std::endl;
std::cout << "entering nearest neighbor location" << std::endl;
L.clear();
random_points_in_range(n/10,dimension,-m,m,L);
timer.reset();
timer.start();
i = 0;
for(it = L.begin(); it!=L.end(); ++it) {
T.nearest_neighbor(*it); i++;
if (i%10==0) std::cout << i << " points located" << std::endl;
}
timer.stop();
std::cout << "used time for location " << timer.time() << std::endl;
T.print_statistics();
std::cout << "done" << std::endl;
return 0;
}
示例3: select
Content& Content::updatePlayer(const std::string &steamID64, const std::string &category, std::unordered_map<std::string, int> stats) {
char *errMsg;
stringstream select(stringstream::out), upsert(stringstream::out);
int id= Utils::hashCode(steamID64 + "-" + category);
vector<string> newStats(stats.size());
auto playerTable= [&stats](void *tableName, int argc, char **argv, char **colName) -> int {
vector<string> statPairs= Utils::split(argv[3], ',');
for(auto it= statPairs.begin(); it != statPairs.end(); it++) {
vector<string> keyval= Utils::split(*it, '=');
if (stats.count(keyval[0]) == 0) {
stats[keyval[0]]= atoi(keyval[1].c_str());
} else {
stats[keyval[0]]+= atoi(keyval[1].c_str());
}
}
return 0;
};
select << "select * from player where id=" << id;
sqlite3_exec(db, select.str().c_str(), playerTable, NULL, &errMsg);
for(auto it= stats.begin(); it != stats.end(); it++) {
stringstream keyval(stringstream::out);
keyval << it->first << "=" << it->second;
newStats.push_back(keyval.str());
}
upsert << "replace into player (id, steamid, stats, category) values (" <<
id << ", coalesce(( select steamid from player where id=" << id << "),\'" << steamID64 << "\'), \'" <<
Utils::join(newStats, ',') << "\', coalesce(( select category from player where id=" << id << "),\'" << category << "\'));";
sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg);
return *this;
}
示例4: GetApuesta
unsigned int GetApuesta(unsigned int &Dinero){
echo();
int bet;
bool ValidBet=false;
while(!ValidBet){
mvprintw(20,0,"Ingrese apuesta (Si no desea seguir jugando, apueste 0): ");
char actual;
int TempBet;
string getbet="";
while((actual=getch())!=10){
if(actual>47&&actual<58){
getbet.push_back(actual);
}
}
TempBet=atoi(getbet.c_str());
if(Dinero<TempBet){
mvprintw(23,0,"Apuesta invalida, no puede apostar una cantidad mayor a su dinero actual (%d)",Dinero);
}else{
bet=TempBet;
Dinero-=bet;
ValidBet=true;
}
}
noecho();
return bet;
}
示例5: main
int main()
{
int i = atoi( "2593" ); // convert string to int
cout << "The string \"2593\" converted to int is " << i
<< "\nThe converted value minus 593 is " << i - 593 << endl;
return 0;
} // end main
示例6: String2Int
int String2Int (string& iStlString)
{
// stringstream theTmpStream (iStlString);
// int theRetInt;
// theTmpStream >> theRetInt;
// return theRetInt;
return atoi (iStlString.c_str());
}
示例7: contentLength
int WebRequest::contentLength() const
{
std::string lenstr = envValue("CONTENT_LENGTH");
if (lenstr.empty())
return 0;
else
return atoi(lenstr.c_str());
}
示例8: assign
void Version::assign(const std::string new_version) {
string tempStr;
vector<string> parts;
size_t i= 0;
while(i < new_version.size()) {
if (new_version[i] == SEPARATOR && !tempStr.empty()) {
parts.push_back(tempStr);
tempStr.clear();
} else {
tempStr+= new_version[i];
}
i++;
}
if (!tempStr.empty()) {
parts.push_back(tempStr);
}
major = atoi(parts.at(0).c_str());
minor = atoi(parts.at(1).c_str());
step = atoi(parts.at(2).c_str());
}
示例9: test_main
int test_main( int argc, char* argv[] )
{
#ifndef BOOST_NO_STDC_NAMESPACE
using std::atoi;
#endif
int n = 100;
if (argc > 1) n = atoi(argv[1]);
test<int>(n);
test<custom>(n);
return 0;
}
示例10: main
int main(int argc, char **argv) {
int port= atoi(argv[1]);
ServerSocket server(port);
cout << "Listening on port: " << port << endl;
while(true) {
Socket client= server.accept();
cout << "Recieved connection from " << client.getAddress() << ":" << client.getPort() << endl;
thread th(handler, &client);
th.detach();
}
return 0;
}
示例11: fin
VoxelBuffer * VoxelBuffer::factory(const string& filename)
{
ifstream fin(filename);
string inputBuffer;
VoxelBuffer * tempBuffer;
fin >> inputBuffer; // "DELT"
fin >> inputBuffer; // Delta value
float delta = (float)atof(inputBuffer.c_str());
fin >> inputBuffer; // "XYZC"
fin >> inputBuffer;
ivec3 dimensions;
dimensions.x = atoi(inputBuffer.c_str());
fin >> inputBuffer;
dimensions.y = atoi(inputBuffer.c_str());
fin >> inputBuffer;
dimensions.z = atoi(inputBuffer.c_str());
tempBuffer = new VoxelBuffer(delta, dimensions);
float tempDensity/*, tempLight*/; // Omit reading in lights temporarily
voxel tempVoxel;
int voxelBufferSize = dimensions.x * dimensions.y * dimensions.z;
tempBuffer->voxels = new voxel[voxelBufferSize];
int i = 0;
// Read in voxel densities (and lights...later)
while (!fin.eof()) {
fin >> inputBuffer;
tempDensity = (float)atof(inputBuffer.c_str());
tempVoxel.density = tempDensity;
tempVoxel.light = -1.0;
tempBuffer->voxels[i++] = tempVoxel; // Add voxel to the 1D array
}
return tempBuffer;
}
示例12: main
int main (int argc, char *argv[]) {
if(argc == 1) {
print();
} else if(argc == 2) {
print(argv[1]);
} else if(argc == 3) {
int times = atoi(argv[2]);
if(times < 1) {
printIllegalArg();
} else {
print(argv[1], times);
}
} else {
printTooManyArgs();
}
}
示例13: main
int main(int argc, char* argv[]){
// First arg should be smallest power of 10 for h
// Hardwired things:
float x_f = sqrt(2);
double x_d = sqrt(2); // doesn't look like sqrt works w/ long double
string output = "/home/claire/phy480/PHY480/warmup/output.csv";
int h_size = atoi(argv[1]);
double *h = new double[h_size];
for (int i=1; i<=h_size; i++){
h[i-1] = pow(10,-i);
//cout << h[i] << endl;
}
/* sizeof float: 4
* sizeof double: 8
* sizeof long double: 16
*/
write_to_file(output,"h",h,h_size);
delete [] h;
// single precision
float *eq1_f = new float[h_size];
deriv_eq1(eq1_f,x_f,h,h_size);
write_to_file(output,"eq1_f",eq1_f,h_size,true);
delete [] eq1_f;
float *eq2_f = new float[h_size];
deriv_eq2(eq2_f,x_f,h,h_size);
write_to_file(output,"eq2_f",eq2_f,h_size,true);
delete [] eq2_f;
// double precision
double *eq1_d = new double[h_size];
deriv_eq1(eq1_d,x_d,h,h_size);
write_to_file(output,"eq1_d",eq1_d,h_size,true);
delete [] eq1_d;
double *eq2_d = new double[h_size];
deriv_eq2(eq2_d,x_d,h,h_size);
write_to_file(output,"eq2_d",eq2_d,h_size,true);
delete [] eq2_d;
return 0;
}
示例14: Set
void CONFIGVARIABLE::Set(string newval)
{
newval = strTrim(newval);
val_i = atoi(newval.c_str());
val_f = atof(newval.c_str());
val_s = newval;
val_b = false;
if (val_i == 0)
val_b = false;
if (val_i == 1)
val_b = true;
if (strLCase(newval) == "true")
val_b = true;
if (strLCase(newval) == "false")
val_b = false;
if (strLCase(newval) == "on")
val_b = true;
if (strLCase(newval) == "off")
val_b = false;
//now process as vector information
int pos = 0;
int arraypos = 0;
string::size_type nextpos = newval.find(",", pos);
string frag;
while (nextpos < /*(int)*/ newval.length() && arraypos < 3)
{
frag = newval.substr(pos, nextpos - pos);
val_v[arraypos] = atof(frag.c_str());
pos = nextpos+1;
arraypos++;
nextpos = newval.find(",", pos);
}
//don't forget the very last one
if (arraypos < 3)
{
frag = newval.substr(pos, newval.length() - pos);
val_v[arraypos] = atof(frag.c_str());
}
}
示例15: main
int main(int argc, char* argv[]) {
int liczba{0};
if (argc == 2) {
char* arg = argv[1];
liczba = atoi(arg);
} else {
cout << "Podaj liczbę: ";
cin >> liczba;
}
cout << endl << "dzielniki: ";
for (int dzielnik = 1; dzielnik <= liczba/2; dzielnik++) {
if (liczba % dzielnik == 0) {
cout << dzielnik << " ";
}
}
cout << liczba << endl;
}