2013-03-23 108 views
-1

编译器每次尝试使用uint64执行时都会显示“uint64没有命名类型”这条消息,同样的情况也适用于uint或unit32,我导入了stdint.h但是没用。另一个问题是当我使用int执行时,变量z得到不同的值,像-160000那么值较小,然后是-140000等,随后的每次执行都是如此。如何解决?这里是代码uint64没有命名一个类型

#include <Windows.h> 
#include <ctime> 
#include <stdint.h> 
#include <iostream> 
using std::cout; 
using std::endl; 
#include <fstream> 
using std::ifstream; 

#include <cstring> 

/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both 
* windows and linux. */ 

uint64 GetTimeMs64() 
{ 
    FILETIME ft; 
    LARGE_INTEGER li; 

    /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it 
    * to a LARGE_INTEGER structure. */ 
    GetSystemTimeAsFileTime(&ft); 
    li.LowPart = ft.dwLowDateTime; 
    li.HighPart = ft.dwHighDateTime; 

    uint64 ret; 
    ret = li.QuadPart; 
    ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */ 
    ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ 

    return ret; 
} 

const int MAX_CHARS_PER_LINE = 512; 
const int MAX_TOKENS_PER_LINE = 20; 
const char* const DELIMITER = "|"; 

int main() 
{ 
    // create a file-reading object 
    ifstream fin; 
    fin.open("promotion.txt"); // open a file 
    if (!fin.good()) 
     return 1; // exit if file not found 

    // read each line of the file 
    while (!fin.eof()) 
    { 
     // read an entire line into memory 
     char buf[MAX_CHARS_PER_LINE]; 
     fin.getline(buf, MAX_CHARS_PER_LINE); 

     // parse the line into blank-delimited tokens 
     int n = 0; // a for-loop index 

     // array to store memory addresses of the tokens in buf 
     const char* token[MAX_TOKENS_PER_LINE] = {}; // initialize to 0 

     // parse the line 
     token[0] = strtok(buf, DELIMITER); // first token 
     if (token[0]) // zero if line is blank 
     { 
      for (n = 1; n < MAX_TOKENS_PER_LINE; n++) 
      { 
       token[n] = strtok(0, DELIMITER); // subsequent tokens 
       if (!token[n]) break; // no more tokens 
      } 
     } 

     // process (print) the tokens 
     for (int i = 0; i < n; i++) // n = #of tokens 
      cout << "Token[" << i << "] = " << token[i] << endl; 
     cout << endl; 
    } 
    uint64 z = GetTimeMs64(); 
    cout << z << endl; 
    system("pause"); 
} 
+0

你安装了64位编译器吗?你安装了哪个版本的Windows和哪个版本的编译器? – 2013-03-23 02:59:59

+1

是不是'uint64_t'的名字? ..或'uint16_t'或'uint32_t'因为这个问题.. – scones 2013-03-23 03:00:39

回答

4

该类型被命名为uint64_t。这同样适用于uint32_tuint16_tuint8_t

uint不存在。你可能只是打算unsigned int

+0

uint64_t运行良好,并且z的结果是一致的,在此感谢 :http://msdn.microsoft.com/zh-cn/library/system.uint64 .aspx uiny64被提及为64位无符号整数。 – Hawk 2013-03-23 03:10:11