Input/output trouble cause segmentation fault
Dear advanced c/g++ programers:
A program request me to enter twice input
that program probably is tested good on visual c++ 7.1 on window xp,
but my system is g++(4.5.2) on linux(Ubuntu10.
It assume
Enter some strings: a b c d
^Z
Enter some more strings: d e f g
^Z
Union: a b c d e f g
Difference: a b c
Intersection: d
all these you can get from page 273 and 274 of book(c++ cookbook)
but my test result is
-------
eric@eric-
Enter a series of strings: a b c d
^Z
[7]+ Stopped ./a.out
eric@eric-
Enter a series of strings: a b c d
{a, b, c, d}
Segmentation fault
-------
second case , I used <Enter><Control-D>
first case, I used <Enter><Control-Z>
the following is the program I tested, you still can download from
http://
-------
// Example 7-8. Unsing set operations
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <iterator>
#include "utils.h" // For parintContainer(): see 7.10
using namespace std;
int main() {
cout << "Enter some strings: "
istream_
istream_
set<string> s1(start, end);
cin.clear();
cout << "Enter some more strings: ";
set<string> s2(++start, end);
set<string> setUnion;
set<string> setInter;
set<string> setDiff;
set_union(
set_differenc
cout << "Union:\n";
printContaine
cout << "Difference:\n";
printContaine
cout << "Intersection:\n";
printContaine
}
-------
utils.h
-------
// Example 7-12. Writing your own printing function
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
template<typename C>
void printContainer(
{
printRange(
}
template<typename Fwd>
void printRange(Fwd first, Fwd last, char delim = ',', ostream& out =
cout) {
out << "{";
while (first != last) {
out << *first;
if (++first != last)
out << delim << ' ';
}
out << "}" << endl;
}
-------
Ned and thanks your help a lot in advance
Eric
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Edward Benson for more information if necessary.