首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

素数有关问题 高手帮忙

2012-02-15 
素数问题 高手帮忙.我做了个素数的问题,要求判断文档里的数是否为素数并且把其顺序输出,如2结果为:1324060

素数问题 高手帮忙.
我做了个素数的问题,要求判断文档里的数是否为素数   并且把其顺序输出,如
2       结果为:1
3                     2
4                     0
6                     0
13                   6
我的做法是:

#include   <iostream>
#include <vector>
#include <fstream>
#include <string>
using   namespace   std;
void   main()
{    
int   b[2000],k=1,count,va;
vector <int> prime(10000,1);
  for(int   i=2;i <100;i++)
  if(prime[i])
  for(int   j=i;j*i <10000;j++)
  prime[i*j]=0;
  for(int   a=2;a <10000;a++)
  if(prime[a])
              b[k++]=a;
                  count=k;
  ifstream   in( "prime.txt ");
        for(string   s;   getline(in,s);)
          for(istringstream   sin(s);sin> > va;)
  if(prime[va])
              for(k=1;k <count;k++)
            if(b[k]==va)
  cout < <k < <endl;
              cout < < "0 " < <endl;
}
                  编译错误如下:
    :\Documents   and   Settings\lhb\11.cpp(20)   :   error   C2079:   'sin '   uses   undefined   class   'basic_istringstream <char,struct   std::char_traits <char> ,class   std::allocator <char>   > '
C:\Documents   and   Settings\lhb\11.cpp(20)   :   error   C2440:   'initializing '   :   cannot   convert   from   'class   std::basic_string <char,struct   std::char_traits <char> ,class   std::allocator <char>   > '   to   'int '
                No   user-defined-conversion   operator   available   that   can   perform   this   conversion,   or   the   operator   cannot   be   called
Error   executing   cl.exe.

[解决办法]
#include <sstream> //缺少这个头文件了
[解决办法]
istringstream 需要包含上面的头文件才可用

热点排行