字符串流的输入问题
该程序是对remainder.txt文件中的成对字符串进行操作,对于第一个字符串,要去掉两个字符串中相同的部分,并按字符顺序输出
remainder.txt文件内容为:
computer program
Write program
thatwill askthe
whole number
******************************
程序如下:
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
int main()
{
ifstream in("remainder.txt");
for (string s,t,u;in>>s>>t;u="")
{
sort(s.begin(),s.end());
sort(t.begin(),t.end());
set_difference(s.begin(),s.end(),t.begin(),t.end(),back_inserter(u));
cout<<u<<endl;
}
return 0;
}
编译的时候出现如下错误:
Deleting intermediate files and output files for project 'ch0515 - Win32 Debug'.
--------------------Configuration: ch0515 - Win32 Debug--------------------
Compiling...
ch0515.cpp
e:\my program\ch05\ch0515.cpp(11) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversi
on)
e:\my program\ch05\ch0515.cpp(17) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversi
on)
Error executing cl.exe.
ch0515.exe - 2 error(s), 0 warning(s)
请高手指点~~