开发者

C++ Netbeans cout error

I never had these errors in dev C++. When i use cout in Netbeans its giving me no match for operator error. This is my program

#include <cstdlib> #include <fstream> #include <iostream> using namespace std;

int main() { //read file fstream fileStream; string tempStr; string strText; fileStream.open("fincode.h开发者_StackOverflow中文版tm", ios::in); while(!fileStream.eof()) { fileStream >> tempStr; strText += tempStr; cout >> strText; }

fileStream.close();
return 0;

}

I get the following errors when i build it


main.cpp: In function ‘int main()’:
make[1]: Leaving directory `/home/user/NetBeansProjects/read_page2'
main.cpp:31: error: no match for ‘operator>>’ in ‘std::cout >> strText’
make[2]: * [build/Debug/GNU-Linux-x86/main.o] Error 1
make[1]: * [.build-conf] Error 2
make: *** [.build-impl] Error 2

I dont get any errors if i remove cout. Any idea whats going on?


You need:

#include <string>

Also, your while-loop is wrong - you should not normally use the eof() function as a loop control - use:

  while( fileStream >> tempStr )
   {
     strText += tempStr;
     cout << strText;      // note operator <<
   }

And I just noticed that your cout statement was incorrect too.


Add

#include <string>

And change

cout >> strText;

To

cout << strText; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜