Tuesday, January 29, 2013

How do I read in file names in a directory for C++?

Q. I'm making a program in C++ using Linux and I have a folder in which there lies 25 different word documents. I am going to create a loop to open each document and browse it, but I am unsure of how to get the names of the documents out of that folder so that I can open them for file transfer.

Does anyone know how I could do this? Thanks.

A. Read this - http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface

I wrote a simple program, you can modify it as you wish:

#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

//Nice function to have
int getdir (string dir, vector<string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}

while ((dirp = readdir(dp)) != NULL) {
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}

int main()
{
string dir = string(".");
vector<string> files = vector<string>();

getdir(dir,files);

for (unsigned int i = 0;i < files.size();i++) {
cout << files[i] << endl;
}
return 0;
}

Problem after removing Vector Linux?
Q. I installed vector linux on my system along with windows and then removed it. After the computer restarted, I got the following message:

error: unknown filesystem.
Entering rescue mode...
grub rescue>

I am using a Sony Vaio laptop and tried 'restore and recovery' using 'Vaio Care'. But the process needs a restart and I get the same error message after restarting. Please help me out.

A. You've deleted grub, which was the boot system.  Startup your computer with a Windows installation disc, and choose repair.  From the repair console, get a command line prompt.  Type in:

fixmbr

and press Enter.  Your computer should now boot to Windows normally.
 

What is the best open source logo making software for Linux?
Q. I'm looking for a free, open source application for Linux which will allow me to make and tweak logos for web and print. Any ideas? I know that Gimp is good for editing raster stuff but I was thinking along the lines of starting on the vector side. Any help would be much appreciated!

A. A few of my favorites are:

http://sk1project.org/
http://www.inkscape.org/
http://www.koffice.org/karbon/
http://www.xaraxtreme.org/

Each one has its pros and cons, but if you go through each of the web-sites, you can see some examples, demos and tutorials of the various features of each.



Nec Projector Review

Plastic Shed Reviews

Ati Graphic Reviews

Nurse Uniforms Reviews

Cabochons Reviews

Inflatable Water Slides Reviews

Barcode Scanner Reviews

No comments:

Post a Comment