Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

knapak

@knapak
About
Posts
49
Topics
17
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • While debugging linker can't open *.exe file because it still is in use
    K knapak

    Hello I'm debugging code created using another programming environment (called AD model builder or ADMB) that generates C++ code. To do this, I have to make the following changes in the project settings: - Add program_name.tpl to your project. Where program_name.tpl is some sort of template (not in the sense of C++ templates) that has the original code that is then translated to C++. - Click on program_name.tpl then on the Project menu, choose settings, in the Custom Build tab, Commands window, add: C:\ADMB\BIN\TPL2CPP.EXE $(InputName) move $(InputName).htp $(WkspDir) In the Output window put: $(InputName).cpp TPL2CPP.EXE is the aplication that translates the ADMB template into C++. (a) When creating the new project create a blank 32 bit Windows console application in the folder where the source files are. (b) In Project/Settings/C++/Code generation, ensure that the runtime library is Debug single-threaded. (c) In Project/Settings/C++/Preprocessor/Preprocessor definitions add __MSVC32__ to the list so the list is: WIN32,_DEBUG,_CONSOLE,_MBCS,__MSVC32__ (d) In Project/Settings/ C++/Preprocessor/Additional include directories add the folder where the ADM include files are, as well as the source folder for the current program e.g. c:\admodel\include,c:\admodel\examples\kalman-filter (e) In Project/Settings/Link/General delete the Object/library models shown and add the ADM ones: admod32.lib adt32.lib ads32.lib (f) In Project/Settings/Link/Input add the ADM library folder - e.g. c:\admodel\lib Then, while debugging the code, if I have to make changes to the program_name.tpl file and try to recompile the resulting C++ it compiles OK but the linker can't access the exe file for modification because apparently is still in use even when I stop debugging clicking on the "stop debugging" button.... Then I tried deleting the exe file but got a message that it is in use by another application but it doesn't show up neither in the applications or processes running in the system... pretty weird... Any ideas about why this is happening and how to solve it? Thanks

    C / C++ / MFC c++ wpf ai-coding debugging tutorial

  • Problem about output files
    K knapak

    Can you explain? Portability? How do you use SetConsoleCursurPosition? I'm writing to a file not sending out to console. Thanks

    C / C++ / MFC question ios help

  • Problem about output files
    K knapak

    Yeah that works... I was wondering if there was a direct way to format the output in columns. Thanks!

    C / C++ / MFC question ios help

  • Problem about output files
    K knapak

    Hi all I have a code that runs a simulation producing numeric outputs of a time series multiple times. I don't know in advance how long is the series or how many times the simulation will run (defined by user at run time). I would like to have the program to write the results out to a file in one column per simulation run instead of a single column where the result of each simulation is separated by some marker. The code to write the output in one column would be something like this: ofstream WriteOutput(OutputData.out,ios::app) for(sim=1; sim<=nsims; sim++) { for(t=1; t<=n; t++) { y=f(x[t]); WriteOutput >> y >> endl; if(t==n) WriteOutput >> "#" >> endl; } } This produces an output like this: 3 4 5 6 # 4 5 6 7 # Instead, I'd like a code to write an output such as: 3 4 4 5 5 6 6 7 How can I do this? Thanks! C.

    C / C++ / MFC question ios help

  • An unusual way to declare an array?
    K knapak

    Thanks for your suggestion. I was trying to avoid using containers. However, Mr. khan++ gave me an idea that solves my problem. Cheers

    C / C++ / MFC question database data-structures

  • An unusual way to declare an array?
    K knapak

    Thank you, this certainly allows me to do what I need... although I was expecting a new way to declare the array instead of a clever way to work with what we already have... but hey, it works for me! Cheers

    C / C++ / MFC question database data-structures

  • An unusual way to declare an array?
    K knapak

    I meant to say: myarray[size]

    C / C++ / MFC question database data-structures

  • An unusual way to declare an array?
    K knapak

    Hi Consider an array that could be indexed as: int firstyear = 1980; int lastyear = 1985; /* where both firstyear and lastyear are not constants*/ int myarray(fistyear,lastyear) /* I know that this is wrong in the regular way to declare an array but this is what I'm looking for. So that I can access it in any of the following ways */ myarray[1981] = 6789; myarray[1983] = 3482; // or work with a loop such as for(int i = firstyear; i <= lastyear; i++) { myarray[i]; } This contrasts with the usual: const int size = 6; int myarray[6]; myarray[1] = 6789; myarray[3] = 3842; // or for(int i = 0; i < size; i++) { myarray[i]; } Hope this makes it clearer. Thanks for your help C.

    C / C++ / MFC question database data-structures

  • An unusual way to declare an array?
    K knapak

    Hello everyone Traditionally, unidymensional arrays are declared by providing the size of the array with a constant number as argument (e.g. myarray[size] where size is usually a const int). I'm working building a model that needs arrays with one value per year (e.g. 6789 in 1989, 3992 in 1990 and so forth). In other words, I need to access values in the array when I have the year of interest as the index to identify the elements of the array. How can I declare the array as myarray(firstyear,lastyear) so I can access its elements the way I need and both firstyear and lastyear are read from a file? Thanks C.

    C / C++ / MFC question database data-structures

  • Serial number storing
    K knapak

    From the msdn website: "Note that the __int8 data type is synonymous with type char, __int16 is synonymous with type short, and __int32 is synonymous with type int". However, if you use MS VC++ on windows, the max integer value you can use with int is 32,767 if signed or twice that if unsigned. What you need is a long int that can take 2,147,483,647 or twice that if unsigned. If you need bigger values then __int64 works... partially... there seems to be a whole lot of things that are not supported for that data type in C++ but seem to work fine in C. Cheers

    C / C++ / MFC question

  • Reading a CSV file
    K knapak

    Fine, if you are mostly writing programs that deal with strings of characters, I can see the problem. However, it seems that were are here talking about reading ONLY numeric data, in which case my approach won't fail and IS SIMPLER. Nevertheless, if you think your solution is more "elegant" why don't you provide a more comprehensive response, something beyond "use this", with clear sample code. Cheers

    C / C++ / MFC c++ tutorial

  • Create Random number
    K knapak

    Hello In my opinion, a better way to do what you need is to use one of the random number generator routines in "NUMERICAL RECIPIES": http://www.library.cornell.edu/nr/cbookcpdf.html Scroll down to Ch. 7 in that page and you'll find a lot of algorithms that will be by far better you can come up using only your machine generator. You'll still need it, but the algorithms provide better "randomness" in your numbers and they are sorted by the way you need them to have certain statistical distributions. If you need them to have equal probabilities, then use the ran2 algorithm. This code is an implementation of it: seed = 0; srand (time(NULL)); rand(); seed = rand(); return ran2(seed); The return number is a uniform random deviate between 0 and 1. If you need integers just multiply your number as needed and take the integer. Cheers

    C / C++ / MFC c++ tutorial question lounge

  • Using a #include in a struct
    K knapak

    Thank you for your response, this certainly proves that there's always someone who knows more that can shame those arrogants that mocked those who knew less... great lesson.

    C / C++ / MFC question

  • Using a #include in a struct
    K knapak

    Hi Sorry to interfere with this discussion. As a novice programmer, I come to this boards to ask for advice about things that I don't know or don't understand. Very often I get invaluable help but unfortunately also very often I only get replies like this... "That would never work"... "Anyone coding like this should be fired"... etc etc etc. If we come to ask a question is not because we are stupid but because we don't have the knowledge, and actually whoever claims that he or she knows everything about C, C++, C#, etc. and is infallible MUST actually be fired. Bottom line, if you want to help, make constructive comments, explain why things would work or wouldn't, provide sample code and refrain yourself from the impulse to riducule those who know less than you... there's always someone out there that knows more than you. Cheers Carlos

    C / C++ / MFC question

  • Reading a CSV file
    K knapak

    It would be more useful if you could explain why this can hardly work and provide examples of the alternatives. I've used it extensively and had no problems at all, but if there's a good reason to do something else we would be very happy to oblige. Otherwise is just empty discourse. Every time you assign a value to a variable, it takes the new value. If the variable is not used at all, given it is a single char variable, virtually no memory is wasted... why wouldn't it work?:wtf:

    C / C++ / MFC c++ tutorial

  • Reading a CSV file
    K knapak

    Hi There may be other more elegant ways, but unless you are reading millions of entries, this works just fine. The char variable is read and then ignored, you only store or use the datx as you wish. char separator; ifstream FileIn("C:\\SampleData\\divedata.dat"); FileIn >> dat1 >> separator >> dat2 >> separator >> dat3 >> separator >> dat4; Good luck

    C / C++ / MFC c++ tutorial

  • reading data from a data file
    K knapak

    Hello David If you think that you've got only half the answer you need... you are not the only one! Often I get very well intentioned replies but full with the assumption that we are all engineers... Anyway, here's what I use to read realtively small files. If reading the file takes more than a few minutes, the decision to use this method or any other depends on how many times during the execution of the program you have to read the file. If you only read it once, go check the scores of the latest soccer games while the computer works. If you need to read the file many times, then it is better to transform your data file into a binary file (if you need it I can also send you code for that). You'll have to wait once while the file is converted but once your data is in binary, reading it from your program is lightning fast. OK, here's the code to read a text file regardless of the file extension. Note that I made the code general so that the first header lines can be one or more. You can choose to change the cin inputs if you know in advance what the will always be (i.e. one header line). Also, please note that the data being read by this program is comma separated. If you don't have commas, use the next commented line. If your data files have a variable amount of lines (e.g. you don't always have the same amount of rows) use a vector container to store your data. Don't hesitate to ask if you have more questions. #include #include using namespace std; int main() { char stuff[100]; int period, stufflines; double dat1, dat2, dat3, dat4, integ, fraction; char separator; int counter; cout << " " << endl; cout << "how many lines with stuff at the beginning?" << endl; cin >> stufflines; cout << " " << endl; ifstream FileIn("C:\\SampleData\\divedata.dat"); if(!FileIn.is_open()) cout << "Could not open the file! Check directory..." << endl; else cout << "You're good, input file opened!" << endl; counter = 1; while(!FileIn.eof()) { if(counter <= stufflines) FileIn.getline (stuff, 100); else { FileIn >> dat1 >> separator >> dat2 >> separator >> dat3 >> separator >> dat4; // FileIn >> dat1 >> dat2 >> dat3 >> dat4; // if no commas } counter++; } return 0; } Good luck Carlos

    C / C++ / MFC tutorial

  • a very looooong integer
    K knapak

    Hi geeks... I mean guys guys...:laugh: I need to use a very large integer that does not fit in a long. So I attempted using _int64 and the values are at least stored in the declared variable. However if I try to send it to the screen, it gives me this compiler error... error C2593: 'operator <<' is ambiguous Can anyone give me a simple explanation and solution? Is there any other place I need to be aware of where I'll run into trouble if using this data type? Thanks a bunch!!!

    C / C++ / MFC help question

  • Commented data file?
    K knapak

    That sounds as if you were recommending to read both the data and the comment and then just ignore/destroy the comment read. If so, that is something I don't want to do. I want to read the data only and if a comment is found ignore it, do not read it. Thanks!

    C / C++ / MFC question learning

  • Commented data file?
    K knapak

    uh... either I didn't make myself clear or I didn't understand your response. Of course I know that INSIDE THE CODE I can use // or /*...*/. The question is how do I comment in a file to be read by the program, making the program ignore the comment... just the same as in the code but while reading the file. Say I have the following code: int main() { int id; double Stuff; ifstream GetData; GetData.open("D:\\SSL\\Code\\Testing_Rutines\\FileComms\\comms.dat"); if (! GetData.is_open()) { cout << "Error opening data file" << endl; exit (1); } else cout << "Commented file opened" << endl; while(!GetData.eof()) { GetData >> id >> Stuff; cout << id << Stuff; } GetData.close(); return 0; } And the data file has (with comments): // first 1 2.3 // second 2 3.5 // third 3 9.8 where the program needs to ignore "// first" , "// second" and "// third". If your response is that I need to "define a character sequence to indicate a comment" I have absolutely no idea how to do it. Both // and /*...*/ are already defined in C++ as comments inside the code, I don't have to define anything. Thank you!

    C / C++ / MFC question learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups