VC编译器下如何解决error C2679、error C2676、error C2784、fatal error C1903错误

本文介绍了在VC编译器下遇到的C2679、C2676、C2784和致命错误C1903,通过分析错误原因,发现是使用std::string与iostream操作符的问题。通过添加#include<string>头文件,解决了在不同编译器下的兼容性问题,使得代码能在GNU和VC编译器下都能正常编译运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近编写了一小段程序,在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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值