storing filenames in an array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: storing filenames in an array

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    storing filenames in an array

    Hello,
    I want to create filenames such as Query.student.1.bin and save them in an array.
    I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)

    string *filename_str;
    filename_str =new string[Number_X_Axis];
    for(i=0;i<Number_X_Axis;i++)
    filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";

    I would appreciate any of your comments on this.

    Best
    PA

  2. #2
    Join Date
    Apr 1999
    Posts
    27,424

    Re: storing filenames in an array

    Code:
    string *filename_str;
    filename_str =new string[Number_X_Axis];
    Learn to use vectors.
    Code:
    #include <vector>
    #include <string>
    typedef std::vector<std::string> StringArray;
    //...
    StringArray filename_str(Number_X_Axis);
    for(i=0;i<Number_X_Axis;i++)
        filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";
    In this day and age of C++, there is hardly a reason to use new[] / delete[] to create a dynamic array. Use container classes such as vector -- that is what vector is designed for.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 2nd, 2012 at 04:56 PM.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,424

    Re: storing filenames in an array

    Quote Originally Posted by palireza View Post
    I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
    You more than likely corrupted the memory due to incorrect usage of new / delete (which is why you should use containers, so these mistakes are not made).

    In actuality, we don't know what you really did, since you didn't post your actual program that you're running. We don't know the data you're using, the flow of the program, where these lines are called/used, etc. We don't even know what "Table_Name", or convertInt() is.

    Post a full, but simple program that demonstrates the error.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 2nd, 2012 at 05:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center