0

I'm going directly to the question. I make it with reading a files line by line and then merge the strings but need a good explanation how to do it with vectors. My goal is to use a system command (Windows XP, 7) to check directory contents and send them directly to the 'vector sysoutp' as example and then merge it in new file with information from a second file. Any ideas?

Just for example part of my code:

while (getline(myinputfile, line))
    {
        lines++;
        found = line.find(countchars);
        if (found!=string::npos)
        {
            line.erase(int(found) + 4);
            myoutputfile << line << endl;
        }
    }

where myinputfile is filled with 'syscomm', the idea is to be converted with vectors but apparently when I try to do something like getline(cin, tmp) where 'cin' is syscomm nothing happens (well, errors pop-up) :(

Also I have and an error when using this preproccessor directive

#define syscomm system("dir /b | find /i /v ".exe .txt") :

createlist.cpp|15|warning: missing terminating " character [enabled by default]|
createlist.cpp|53|error: missing terminating " character|
createlist.cpp||In function 'int main()':|
createlist.cpp|53|error: request for member 'exe' in '"dir /b | find /i /v "', which is of non-class type 'const char [21]'|
||=== Build finished: 2 errors, 1 warnings ===|

It's working without adding "| find ..." but using it I can filter not needed file names with their known extensions.

Thanks for cooperation and sorry for 2-in-1 question pack :)

1000Gbps
  • 1,455
  • 1
  • 29
  • 34
  • One question at a time, please. – Konrad Rudolph Feb 08 '12 at 11:19
  • So what's the basic algorithm for reading line by line from a command output and inserting them in the vector for the following sort action? I know how to do the sort but the reading is hard to understand ... Did: `while (!inputcomm.eof()) { sortedvector.push_back(inputcomm.getline(buffer, 10)); } sort(sortedvector.begin(), sortedvector.end()); pclose(inputcomm); return sortedvector;` where inputcomm is for example `FILE *inputcomm = popen("dir /b | findstr /i \"\\<*.sd\"", "rt");` :( – 1000Gbps Feb 12 '12 at 08:45

1 Answers1

0

Check that #define again...

#define syscomm system("dir /b | find /i /v ".exe .txt")
// String starts here -^                    ^
// String ends here ------------------------'

Should be very visible in your editor if it has syntax coloring.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Yeah, my mistake, forgot to close the quotes, but it still outputs exec and txt filenames :| – 1000Gbps Feb 08 '12 at 12:51
  • @1000Gbps Double-quotes inside a string has to be escaped, like this: `"string \" containing \" four \" double \" quotes"`. You did that too? – Some programmer dude Feb 08 '12 at 13:11
  • So I must use `"dir /b | findstr /i /v \".exe .txt""?` I forgot that `find` is not working with more than two strings. Must use `findstr`, and now it works :) – 1000Gbps Feb 08 '12 at 13:36