Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: The C Containers library |
| Date | 2015-10-31 12:21 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87twp7b553.fsf@bsb.me.uk> (permalink) |
| References | <n11san$o70$1@dont-email.me> <n129pr$ngg$1@news.albasani.net> |
Johannes Bauer <dfnsonfsduifb@gmx.de> writes:
> On 31.10.2015 09:00, jacobnavia wrote:
>
>> The C++ solution:------------------------------------------
>> #include <vector>
>> #include <fstream>
>> #include <algorithm>
>> #include <string>
>>
>> using namespace std;
>>
>> int main(int argc,char* argv[])
>> {
>> char* file = argv[2]; // input file name
>> char* ofile = argv[3]; // output file name
>>
>> vector<string> buf;
>>
>> fstream fin(file, ios::in);
>> string d;
>> while(getline(fin, d)) buf.push_back(d); //add line to buf
>>
>> sort(buf.begin(), buf.end());
>>
>> fstream fout(ofile, ios::out);
>> copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
>>
>> }
>
> Doesn't compile for me. Has probably UB (return missing).
>
> $ g++ -Wall -std=c++11 -O3 foo.cpp
> foo.cpp: In function ‘int main(int, char**)’:
> foo.cpp:22:34: error: ‘ostream_iterator’ was not declared in this scope
> copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
> ^
> foo.cpp:22:57: error: expected primary-expression before ‘>’ token
> copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
> ^
> foo.cpp:22:64: warning: left operand of comma operator has no effect
> [-Wunused-value]
> copy(buf.begin(), buf.end(),
> ostream_iterator<string>(fout,"\n"));
There's a missing #include <iterator>.
>> #include <containers.h>
>>
>> int main(void)
>> {
>> strCollection *myData =
>> strCollection.CreateFromFile("mydata.txt");
>> strCollection.Sort(myData);
>> strCollection.WriteToFile(myData,"mySortedData.txt");
>> return 0;
>> }
>
> Doesn't compile for me.
>
> $ gcc -O3 -Wall foo.c -I .
> foo.c: In function ‘main’:
> foo.c:7:9: error: expected expression before ‘strCollection’
> strCollection.CreateFromFile("mydata.txt");
> ^
> foo.c:8:18: error: expected identifier or ‘(’ before ‘.’ token
> strCollection.Sort(myData);
> ^
> foo.c:9:18: error: expected identifier or ‘(’ before ‘.’ token
> strCollection.WriteToFile(myData,"mySortedData.txt");
> ^
> foo.c:6:20: warning: unused variable ‘myData’ [-Wunused-variable]
> strCollection *myData =
> ^
Yes, I get the same errors. Maybe Jacob has changed his library, but
the version I once looked at needed istrCollection.Whatever.
When both compiled with -O3 they run at about the same speed for at
least one test file (140,000 lines of English text, with average line
length 36 characters). The C++ one is slightly faster but it's very
close.
Of course, it's an odd test. C with a high-level string library vs. C++
is not really C vs C++.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 09:00 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 10:22 +0100
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 02:46 -0700
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:41 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 12:48 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 12:21 +0000
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 14:31 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 13:35 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 14:33 +0100
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:45 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-10-31 13:46 -0700
Re: The C Containers library Robert Wessel <robertwessel2@yahoo.com> - 2015-11-01 01:31 -0500
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-01 20:34 +1300
Re: The C Containers library Robert Wessel <robertwessel2@yahoo.com> - 2015-11-01 01:38 -0500
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 01:22 -0800
Re: The C Containers library Richard Heathfield <rjh@cpax.org.uk> - 2015-11-01 09:20 +0000
Re: The C Containers library supercat@casperkitty.com - 2015-11-01 07:51 -0800
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 15:57 +0000
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 17:41 +0100
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 16:53 +0000
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 12:01 -0500
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 22:44 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-11-05 11:16 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-05 09:24 -0800
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:23 +0100
Re: The C Containers library Melzzzzz <mel@zzzzz.com> - 2015-10-31 16:33 +0100
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 11:51 -0700
Re: The C Containers library Melzzzzz <mel@zzzzz.com> - 2015-10-31 22:04 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 19:29 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-10-31 13:40 -0700
Re: The C Containers library "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-11-01 12:09 -0800
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 22:39 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 22:50 +0000
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-02 00:07 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 23:38 +0000
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:11 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-02 08:15 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:27 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:36 -0800
csiph-web