Thread: vector works one set of files, just not freshly created ones, its a no go.

  1. #1
    Banned
    Join Date
    Aug 2017
    Posts
    861

    vector works one set of files, just not freshly created ones, its a no go.

    I was writing a sort function to sort strings with the sort(v.begin(), v.end(), function-call);

    then decided to created some image files with sequential numbering in them so I can use them for a quick look to see if they are sorted,
    1,2,3,4,5,6,7 etc... after calling the function.

    when I ran that function on the newly created files, using blender to get images with numbers already attached to them, quickly. I get file names when sending them into the vector. I get empty space being printed out when I loop through the vector to print out x number files.

    I can switch the directory to load off of and it works, then when i change to that test dir it does not print out file names, it is like running a loop with cout<< "\n"; getting just new lines.

    The files are valid, I ran them in program that proves it. I have no idea what data or code to show because it is working code. as stated it works on one dir filled with image files just not the newly created ones, where a different program(s) see them just find.

    so it is no longer am I sorting properly but, now why it is not picking up the newly created files like it should?

    if you just happen to want to look at the code, yes, I will post it upon request.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,938
    Quote Originally Posted by userxbw
    I get empty space being printed out when I loop through the vector to print out x number files.
    That sounds like the filenames were read, but somehow instead of getting correctly stored in the vector, you ended up with blank entries? I'd suggest running the program in a debugger and examining the content of the vector from the point you start reading the filenames to the point you print them out.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by laserlight View Post
    That sounds like the filenames were read, but somehow instead of getting correctly stored in the vector, you ended up with blank entries? I'd suggest running the program in a debugger and examining the content of the vector from the point you start reading the filenames to the point you print them out.
    why it work on everything else just not that one dir?

    and

    ha, now I got a lean how to run the debugger. SO, what you doing right now? lol

    I am running Linux, any suggestions on a easy one that I can fast load vars to watch? because I don't think one is installed on this distro. (yet) you prob use windows.
    Last edited by userxbw; 10-05-2017 at 05:00 PM.

  4. #4
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by laserlight View Post
    That sounds like the filenames were read, but somehow instead of getting correctly stored in the vector, you ended up with blank entries? I'd suggest running the program in a debugger and examining the content of the vector from the point you start reading the filenames to the point you print them out.
    ok baisc gdb load and run program,
    Code:
    (gdb) set args -a /media/data/test
    (gdb) run
    Starting program: /media/data/projects/VSC/C++/mh5000/a.out -a /media/data/test
    
    
    
    
     b
    terminate called after throwing an instance of 'std::out_of_range'
      what():  vector::_M_range_check: __n (which is 22) >= this->size() (which is 22)
    
    Program received signal SIGABRT, Aborted.
    __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
    51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    if you can't make anything out of that then I got a figure out how to break and such with this debugger.

    I think I found a good page to help me
    Linux Tutorial - GNU GDB Debugger Command Cheat Sheet
    Last edited by userxbw; 10-05-2017 at 05:15 PM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,938
    out_of_range is the standard exception thrown in cases such as accessing a vector by index with at() out of the range of its valid indices.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Banned
    Join Date
    Aug 2017
    Posts
    861
    got it, where I am over running it in a loop. on an if ( check )

    well I stopped the out_of_range error, but it is still not putting out, the file names.
    Last edited by userxbw; 10-05-2017 at 05:31 PM.

  7. #7
    Banned
    Join Date
    Aug 2017
    Posts
    861
    OK, this is silly, as one can see. in one dir it gets files returns the proper data, next dir with newly created files that (seem) to check out with other programs, a file manager sees them and can open them into a different image viewing program. but not here.
    Code:
    [userx@void mh5000]$ ./a.out -a /run/media/userx/3TB-External/wallpaper/vlcsnap
    fsize 240
    newsize 238
     in main v size is = 238
    /run/media/userx/3TB-External/wallpaper/vlcsnap/vlcsnap-00001.png
    [userx@void mh5000]$ ./a.out -a /media/data/test
    fsize 22
    newsize 20
     in main v size is = 20
    
    [userx@void mh5000]$
    guess I got go take some time and figure out this dgb

    telling me something
    Code:
    no such file
    home/sysdeps/x86_64...
    for std::memset cstring header which I have set in the file, but I do not even have a directory called "sysdeps" on my system period. then the debugger locks up, maybe me or maybe ddd
    Last edited by userxbw; 10-05-2017 at 06:10 PM.

  8. #8
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Ha it is not picking up anykind of newly created file whatsoever, just ones that have been around for awhile
    Code:
    [userx@devuan data]$ cd gooby
    [userx@devuan gooby]$ ls
    file1  file2  file3  file4  file5
    [userx@devuan gooby]$ for NUM in `seq 1 1 1000`
    > do
    > touch $NUM-file
    > done
    [userx@devuan gooby]$ ls
    1000-file  170-file  240-file  310-file  381-file  451-file  
    ....
    I put it in a infant itny loop
    Code:
    i 11 
    i 12 
    i 13 
    i 14 
    i 15 
    i 16 
    i 17 
    i 18 
    i 19 
    i 20 
    i 21 
    i 22 
    i 23 
    i 24 
    i 25 
    i 26 
    i 27 /media/data/gooby/file1
    i 28 /media/data/gooby/file1
    i 29 /media/data/gooby/file2
    i 30 /media/data/gooby/file3
    i 31 @�
    i 32 �
    i 33 �6D��
    i 34

  9. #9
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Ha crap, went back to my first idea, use strings.
    Code:
    else if (S_ISREG(st.st_mode))
    { 
    //    std::cout << "files "<< path<<std::endl;
    
        std::stringstream newStringPath;
        newStringPath << path;
        std::string myStringPath = newStringPath.str();
    
         opts.dfile.push_back( myStringPath ); 
        opts.g++;
    }
    as it was printing out proper data before adding it to the vector<char *> and not afterwords, I just convert the char * to a string then pass it into the vector<string>, now it picks up everything. Hopefully it will stay that way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 09-20-2012, 10:06 PM
  2. Code works, one some files but not others
    By Watts53 in forum C Programming
    Replies: 5
    Last Post: 08-05-2010, 12:21 PM
  3. Storing information created files.
    By GCNDoug in forum C Programming
    Replies: 12
    Last Post: 05-07-2007, 03:18 PM
  4. user created header files
    By MedicKth in forum C++ Programming
    Replies: 6
    Last Post: 09-20-2003, 12:36 PM
  5. Replies: 4
    Last Post: 06-22-2002, 01:00 PM

Tags for this Thread