c++ - Mac OS X - get end of line in file -


i try open , read file on mac os x:

file * pfile = fopen (path_.c_str() , "r"); if (pfile == null) {    perror ("error opening file"); } else {    char line [buffer_size]={0};    size_t length=0;    std::vector<unsigned> nodes;    while ((line[length++] = fgetc (pfile)) != eof )    {       printf("%d",line[length-1]);       if (line[length-1] == '\r'||line[length-1] == '\n' #ifdef __apple__     ||line[length-1] == '$' #endif       ) {    line[length-1]=0;    unsigned number = 0;    for(unsigned i=0;i<length;++i)    {       if(isdigit(line[i]))    {       number = number *10+line[i]-'0';    } else    {       nodes.push_back(number);       number = 0;    } }       memset(&line,0,buffer_size);       length=0; } } fclose (pfile); 

i use #ifdef __apple__ define, code work on linux, on mac os x must read symbol defines end of line file/line. how can symbol finished file, without trick?

do in c++:

unsigned number; std::vector<unsigned> nodes; std::ifstream file(path_.c_str()); while (file >> number)     nodes.push_back(number); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -