最近编写了一小段程序,在GNU编译器下能编译通过,但在VC编译器下却显示一大堆错误。查看编译信息,其中错误提示如下:
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 conversion)
fatal error C1903: unable to recover from previous error(s); stopping compilation
这段程序如下所示,程序不断从stdin中读入单词,若该单词是第一次出现,则输出该单词,否则忽略。注:输入中单词以空格间隔,标点符号仅出现在单词后面,且和单词字母间没有其他字符。
例如输入:where there is a will, there is a way.
则应输出:where there is a will way
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
int main()
{
char str[100];
string word;
set<string> words;
while(cin >> str){
int n = strlen(str) - 1;
char c = str[n];
if (!isa