penetrator

Members
  • Content count

    605
  • Joined

  • Last visited

Community Reputation

122 Neutral

About penetrator

  • Rank
    Advanced Member
  1. C++ : trouble with arrays ?

    Ok, let's go for the new libraries, but i got tons of errors ... please teach me ... #include <windows.h> // Header File For Windows #include <stdio.h> // Header File For Standard Input / Output #include <stdarg.h> // Header File For Variable Argument Routines #include <math.h> // Header File For Math Operations #include <iostream> #include <algorithm> #include <string> #include <iostream> using namespace std; template <typename T> void readInto(std::istream& source, T* dest, unsigned int size) { source.read(reinterpret_cast<char *>(dest), size * sizeof(T)); } const unsigned int IDRISI_MAP_X = 256; const unsigned int IDRISI_MAP_Y = 256; const unsigned int IDRISI_SIZE = IDRISI_MAP_X * IDRISI_MAP_Y; unsigned int *idrisipMap = new unsigned int[IDRISI_SIZE]; std::ifstream idrisi("E:/temp/pippo.rst", std::ios::binary); readInto(idrisi, idrisipMap, IDRISI_SIZE); std::ofstream idrisi_out("C:/temp/idrisi_out.txt"); for (int i=0; i < IDRISI_SIZE; i++) { idrisi_out << idrisipMap[i] << ","; } delete[] idrisipMap; and these are the compile errors: Compiling... fileinput.cpp e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(21) : error C2079: 'idrisi' uses undefined class 'std::basic_ifstream<_Elem,_Traits>' with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(21) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(21) : see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(21) : error C2078: too many initializers e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(22) : error C2501: 'readInto' : missing storage-class or type specifiers e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(22) : error C2365: 'readInto' : redefinition; previous definition was a 'function' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(12) : see declaration of 'readInto' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(22) : error C2078: too many initializers e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(24) : error C2079: 'idrisi_out' uses undefined class 'std::basic_ofstream<_Elem,_Traits>' with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(24) : see reference to class template instantiation 'std::basic_ofstream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(24) : see reference to class template instantiation 'std::basic_ofstream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(24) : error C2440: 'initializing' : cannot convert from 'const char [23]' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2059: syntax error : 'for' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2143: syntax error : missing ')' before ';' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2143: syntax error : missing ';' before '<' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2501: 'i' : missing storage-class or type specifiers e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2143: syntax error : missing ';' before '++' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2501: 'i' : missing storage-class or type specifiers e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2086: 'int i' : redefinition e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : see declaration of 'i' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2059: syntax error : ')' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2143: syntax error : missing ';' before '{' e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(26) : error C2447: '{' : missing function header (old-style formal list?) e:\Documents and Settings\terrestrial\Desktop\K-NN.source-lite\fileinput.cpp(30) : error C2059: syntax error : 'delete' NeHe_OpenGL_Basecode - 18 error(s), 0 warning(s)
  2. C++ : trouble with arrays ?

    Thanks guys, now the routine does not crash anymore. However, i'm still no able to get the correct output. The input file is a binary raster file which contains a sort of image map: values should go from 0 to 334. Instead, the idrisi_out.txt is filled with 0's, while i was expecting to have several integer values ranging just from 0 to 334 as well.
  3. Hi, i'm trying to read a binary file containing integers, and then write the file in ascii mode. What i do is this: #define IDRISI_MAP_X 256 #define IDRISI_MAP_Y 256 unsigned int *idrisipMap = (unsigned int *) malloc( IDRISI_MAP_X * IDRISI_MAP_Y ); FILE *idrisi ; idrisi = fopen(project_texture , "rb" ); fread( idrisipMap, 1, IDRISI_MAP_X * IDRISI_MAP_Y, idrisi ); fclose(idrisi); // Finished reading file, now we start to write FILE *idrisi_out ; idrisi_out = fopen("C:\\temp\\idrisi_out.txt" , "w" ); for (int i=0; i<IDRISI_MAP_X * IDRISI_MAP_Y; i++) { fprintf(idrisi_out,"%i,", *idrisipMap++); // this crash the app when i goes > 16384 //fprintf(idrisi_out,","); This works filling the file with , } fclose(idrisi_out); I'm no expert, so i do not know how to use the debugger, and i dont understand what is the problem: seems to me i allocated the idrisipMap pointer correctly, but for some reasons it has an overflow. Thanks Alex
  4. C++ : arrays considerations

    I found that something like this would do: int cippa=1024; int *buff = new int[cippa]; for (int i = 0; i < cippa; i++) { buff[i] = 52; }
  5. I'm building a program that has to load several image files on different sizes and store values in an array. I was planning to have an array such as: float image_data[IMAGE_INDEX][IMAGE_X * IMAGE_Y]; Problem is that since any image will have a different size (i mean different numbers of x and y pixels), and IMAGE_X * IMAGE_Y must be a constant, i can only put an extremely high IMAGE_X * IMAGE_Y value and fill the array. In practice, if the image is 300x300 and IMAGE_X * IMAGE_Y is 1024x1024, i will have an array filled with values and with a long tail of 0's. To my knowledge there is no way to dinamically resize an array in C++ , so i'd like to know what possible "tricks" i might use. Thanks
  6. Opening two opengl windows ?

    Thanks very much, next time i'll google before asking ...
  7. Opening two opengl windows ?

    Hi, two Opengl rendering contexts !
  8. Opening two opengl windows ?

    Thre is any tutorial that explain how to create two opengl windows ? Possibly using Nehe's code ? Thanks
  9. Hi, i've built a procedure to load files using the GetOpenFileName visual module. In practice i do the following: OPENFILENAME ofn3; if (GetOpenFileName(&ofn3)==TRUE) hf = CreateFile(ofn3.lpstrFile, GENERIC_READ,0, (LPSECURITY_ATTRIBUTES) NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL); After a file is selected through the open file dialog box, ofn3.lpstrFile holds the full path file (i.e. "C:\temp\file1.txt") What i do to open the selected file is: idrisi = fopen(ofn3.lpstrFile , "rb" ); Doing this the application crashes, instead doing a: idrisi = fopen("C:\\temp\\file1.txt") , "rb" ); it works. I even strcomp ofn3.lpstrFile "C:\temp\file1.txt" and the do are equal. So i don't quite understand how to make it work. Thanks again
  10. C++ : help replacing string chars

    ops, you were faster then me ;-) Thanks guys !
  11. C++ : help replacing string chars

    ok i found it myself: const char *idrisi_file_to_open= idrisi_file.c_str();
  12. C++ : help replacing string chars

    Thanks, i will try it now. Can you tell me also how to convert a standard std::string to a const char ?
  13. Hi, i need to replace backslash char in a string : char test1[255] = {"C:\temp\ozz\file1.txt"}; so that it becomes equal to C:\\temp\\ozz\\file1.txt I know the use of the std::replace function, but that only replace one char with another. Instead, in this case i want to replace \ with \ Thanks
  14. Directinput question

    I'm still using the good old directx7, and GetDeviceInfo() is not supported. I suppose i will have to switch soon ...
  15. I use directinput to get all the axis, buttons of a joystick, but i don't know how to retrieve the vendor or joystick model name. Anyone tried it ? Thanks