C++ 未识别的cygwin编译错误

C++ 未识别的cygwin编译错误,c++,C++,大家好 我的代码的编译过程有问题。我已经在我当前使用的IDE(Codeblocks)中测试了我的代码,在同一个包含11个单词的目录中使用testfile.txt。我100%肯定我的文本文件不是问题,因为我已经让程序运行完美,没有问题。出现的问题是,当我尝试使用Cygwin64编译代码时(我在一台64位机器上),它抛出了下面总结的错误 代码 #包括 #包括 #包括//打开文件的需要 使用名称空间std; int main(){ string filename=“testfile.txt”;//设置

大家好

我的代码的编译过程有问题。我已经在我当前使用的IDE(Codeblocks)中测试了我的代码,在同一个包含11个单词的目录中使用testfile.txt。我100%肯定我的文本文件不是问题,因为我已经让程序运行完美,没有问题。出现的问题是,当我尝试使用Cygwin64编译代码时(我在一台64位机器上),它抛出了下面总结的错误

代码

#包括
#包括
#包括//打开文件的需要
使用名称空间std;
int main(){
string filename=“testfile.txt”;//设置我们的预默认测试文件
ifstream文件(文件名);//打开文件
字符串;//初始化变量
int wordcount=0;//字数设置为0
/*运算符>>仅跳过前导空格。
/当到达文件中所有单词的末尾时,它停止提取
//对于每个迭代,在字数中添加一个。显示结果。
*/
while(文件>>单词)
{
++字数;
}
cout>单词)
^
然后它列出了来自cygwin图书馆的候选者

阅读此错误后,我使用Codeblocks在不同的文件夹中使用不同的文本文件重新运行/重建此代码,代码正常工作。但是,当我创建新文件并执行相同的过程(即使用cygwin编译)时,我得到了确切的错误


我不太明白为什么操作数与“>>”的匹配有问题——如果我是正确的,这是“input”的通用符号,因此while(文件>>单词)中应该是“while in file transversing through words…”。如果您能帮助我理解此问题,我将不胜感激。

您可能需要设置一些选项以使用C++11而不是C++03。可能会有帮助:您可能需要设置一些选项以使用C++11而不是C++03。可能会有帮助:
#include <iostream>
#include <string>
#include <fstream> // need for opening file

using namespace std;

int main (){

    string filename = "testfile.txt"; // setting our pre-default test file

    ifstream file(filename); // open file
    string words; // initialize variable
    int wordcount = 0 ; // word count set at 0

    /* The operator >> skips only leading whitespace.
    /It stops extracting when it reaches the end of all words in the file
    // for every iteration add one to word count. display results.
    */
    while(file >> words)
    {
        ++wordcount;
    }

    cout<< "The number of words inside the file is : "<<wordcount<<endl;

return 0;
}
$ g++ -o oTMA1Question1 TMA1Question1.cpp
TMA1Question1.cpp: In function 'int main()':
TMA1Question1.cpp:92:13: error: no match for 'operator>>' (operand types are 'std::ifstream() {aka std::basic_ifstream<char>()}' and 'std::string {aka std::basic_string<char>}')
  while (file >> words)
              ^