當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::atol方法代碼示例

本文整理匯總了C++中std::atol方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::atol方法的具體用法?C++ std::atol怎麽用?C++ std::atol使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::atol方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: select

Content& Content::updateAggregate(const std::string &category, const std::string &stat, long value) {
    char *errMsg;
    stringstream select(stringstream::out), upsert(stringstream::out);
    int id= Utils::hashCode(stat + "-" + category);
    auto aggregateTable= [&value](void *tableName, int argc, char **argv, char **colName) -> int {
        value+= atol(argv[2]);
        return 0;
    };

    select << "select * from aggregate where id=" << id;
    sqlite3_exec(db, select.str().c_str(), aggregateTable, NULL, &errMsg);

    upsert << "replace into aggregate (id, stat, value, category) values (" << 
        id << ", coalesce(( select stat from aggregate where id=" << id << "),\'" << stat << "\'), \'" << value << 
        "\', coalesce(( select category from aggregate where id=" << id << "),\'" << category << "\'));";
    sqlite3_exec(db, upsert.str().c_str(), NULL, NULL, &errMsg);

    return *this;
}
開發者ID:scaryghost,項目名稱:KFSXTrackingServerLite,代碼行數:19,代碼來源:Content.cpp

示例2: main

int main(int argc, char *argv[]) {
	if (3 <= argc && argc <= 4) {
		int nbytes= atoi(argv[2]);
		if (nbytes <= 0) {
			cerr << "bitcount: nbytes must be greater than zero\n";
			return EXIT_FAILURE;
		}
		int nthreads= (argc > 3) ? atoi(argv[3]) : 0;
		if (nthreads < 0) {
			cerr << "bitcount: nthreads must not be less than zero\n";
			return EXIT_FAILURE;
		}
		
		vector<unsigned char> space(atol(argv[2]));
		fillMemory(space);

		if (strcmp(argv[1], "shift") == 0) {
			if (nthreads == 0)
				cout << bitCount(&space[0], space.size(), bits_shift);
			else
				cout << bitCount_mt(&space[0], space.size(), nthreads, bits_shift);
			cout << endl;
			return EXIT_SUCCESS;
		}
		if (strcmp(argv[1], "lookup") == 0) {
			if (nthreads == 0)
				cout << bitCount(&space[0], space.size(), bits_lookup);
			else
				cout << bitCount_mt(&space[0], space.size(), nthreads, bits_lookup);
			cout << endl;
			return EXIT_SUCCESS;
		}
	}
	cerr << "Usage: bitcount [shift|lookup] nbytes [nthreads]\n";
	return EXIT_FAILURE;
}
開發者ID:tbfe-de,項目名稱:mc-cpp11-BLWS,代碼行數:36,代碼來源:bitcount.cpp

示例3: main

int main(int argc, char *argv[])
{
	srand(time(NULL));
	FILE *fd;
	static size_t rand_num;
	static long rand_min = 0L;
	static long rand_max = 1000000L;

	fd = fopen("unsorted.txt", "w");
	
	switch(argc) {
	case 2:
		rand_num = atol(argv[1]);
		break;
	case 3:
		rand_num = atol(argv[1]);
		rand_max = atol(argv[2]);
		break;
	case 4:
		rand_num = atol(argv[1]);
		rand_min = atol(argv[2]);
		rand_max = atol(argv[3]);
		break;
	default:
		printf("Usage: %s rand_num\n", argv[0]);
		printf("Usage: %s rand_num rand_max\n", argv[0]);
		printf("Usage: %s rand_num rand_min rand_max\n", argv[0]);
		break;
	}//switch

	for(int i = 1; i <= rand_num; ++i) {
		if(i % 10 == 0)
			fputc('\n', fd);
		fprintf(fd,
				"%ld ",
				(long)(rand() * (rand_max - rand_min)/RAND_MAX
					+rand_min)); 
	}//for
	
	fclose(fd);
	
	return 0;
}//main
開發者ID:adamcavendish,項目名稱:HomeworkGitShare,代碼行數:43,代碼來源:test_file_creator.cpp

示例4: cpp_main

int cpp_main(int argc, char *argv[])
{
  for (int a = 0; a < argc; ++a)
  {
    command_args += argv[a];
    if (a != argc-1)
      command_args += ' ';
  }

  cout << "command line arguments: " << command_args << '\n';

  cout << "*******************************************************************\n"
          "*  WARNING: DUMPING AND RELOADING STATE FOR RESTART NOT WORKING;  *\n"
          "*  COMMENTED OUT CODE NEEDS TO BE FIXED TO RESTART RNG AND        *\n"
          "*  DUMP AND RESTORE mapped_type DATA IF PRESENT.                  *\n"
          "*******************************************************************\n\n";

  for (; argc > 1; ++argv, --argc) 
  {
    if (*argv[1] != '-')
      path_prefix = argv[1];
    else
    {
      if (strncmp(argv[1]+1, "max=", 4) == 0)
        max = atol(argv[1]+5);
      else if (strncmp(argv[1]+1, "min=", 4) == 0)
        min = atol(argv[1]+5);
      else if (strncmp(argv[1]+1, "low=", 4) == 0)
        low = atol(argv[1]+5);
      else if (strncmp(argv[1]+1, "high=", 5) == 0)
        high = atol(argv[1]+6);
      else if (strncmp(argv[1]+1, "cycles=", 7) == 0)
        cycles = atol(argv[1]+8);
      else if (strncmp(argv[1]+1, "seed=", 5) == 0)
        rng_seed = atol(argv[1]+6);
      else if (strncmp(argv[1]+1, "node=", 5) == 0)
        node_sz = atol(argv[1]+6);
      else if (strncmp(argv[1]+1, "cache=", 6) == 0)
        cache_sz = atol(argv[1]+7);
      else if (strncmp(argv[1]+1, "dump=", 5) == 0)
        dump = atol(argv[1]+6);
      else if (strncmp(argv[1]+1, "restart", 7) == 0)
        restart = true;
      else if (strcmp(argv[1]+1, "v") == 0)
        verbose = true;
      else if ( memcmp( argv[2]+1, "sep=", 4 )==0
          && (std::ispunct(*(argv[2]+5)) || *(argv[2]+5)== '\0') )
        thou_separator = *(argv[2]+5) ? *(argv[2]+5) : ' ';
      else
      {
        cout << "Error - unknown option: " << argv[1] << "\n\n";
        argc = -1;
        break;
      }
    }
  }

  if (argc < 2) 
  {
    cout << "Usage: stl_test [Options]\n"
      "The argument n specifies the number of test cases to run\n"
      "Options:\n"
      "   path-prefix  Test files path-prefix; default '" << path_prefix << "'\n"
      "                Two files will be created; path-prefix.btr and path-prefix.stl\n"
      "   -max=#       Maximum number of test elements; default " << max << "\n"
      "   -min=#       Minimum number of test elements; default " << min << "\n"
      "   -low=#       Random key distribution low value; default 0\n"
      "   -high=#      Random key distribution high value; default max*2.\n"
      "                (high-low) must be >max, so that max is reached\n"
      "   -cycles=#    Cycle tests specified number of times; default " << cycles << "\n"
      "                -cycles=0 causes tests to cycle forever\n"
      "   -seed=#      Seed for random number generator; default "  << rng_seed << "\n"
      "   -node=#      Node size (>=128); default " << node_sz << "\n"
      "                Small node sizes increase stress\n"
      "   -cache=#     Cache size; default " << cache_sz << " nodes\n"
      "   -dump=#      Dump restart files when cycles run mod dump # == 0, except \n"
      "                dump # -1 means dump at end only, 0 means never dump;\n"
      "                default " << dump << "\n"
      "   -restart     Restart using restart files from previous run\n"
      "   -v           Verbose output statistics\n"
      "   -sep=[punct] cout thousands separator; space if punct omitted, default -sep,\n"
      "\n    Each test cycle inserts the same random values into both a btree_map\n"
      "and a std::map until the maximum number of elements is reached.\n"
      "The same sequence of random elements will then be erased, until the minimum\n"
      "number of elements is reached. The btree, std::map, and program state are\n"
      "copied to files, and the cycle ends.\n"
      "    At the maximum and minimum points of each cycle, forward iteration,\n"
      "backward iteration, find, lower_bound, and upper_bound tests are run\n"
      "against both containers. If results are not identical, the program\n"
      "issues an error message and returns 1.\n"
      "    The -restart argument causes the btree, std::map, and program to be\n"
      "initialized to the state saved in the restart files from the prior run.\n"
      ;
  }

  if (argc == -1)
    return 1;

  if (high == 0)
    high = max * 2;
//.........這裏部分代碼省略.........
開發者ID:Beman,項目名稱:btree,代碼行數:101,代碼來源:stl_test.cpp


注:本文中的std::atol方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。