error C2501: 'string' : missing storage-class or type specifiers

1.首先正确包含头文件
使用下面语句
#include
没有.h,
否则无法引用标准模板库
2.使用命名空间
即使用下面语句:
using namespace std;
3.string 所创建的对象不能够直接使用里面的字符串
如 string str;
cout<这样语句不能执行
要使用string的一个函数进行转化 c_str() 才能正确使用其中的字符串。

完整的程序代码如下:
所创建的是一个Console 的工程

#include "stdafx.h"
#include "iostream.h"
#include

using namespace std;

struct Rec
{
 char chNum;
 string path;
};
int main(int argc, char* argv[])
{
 printf("Hello World!/n");
 string out[10]=
 {
  "0000000000","1111111111","22222222222","333333333333","4444444444"
   ,"555555","6666666666","7777777","888888","999999"
 };
 struct Rec recInfo[10];
 int cnt = 0 ;
 
 for (int j=0; j<10; j++)
 {
  cnt +=out[j].length();
 }

 char *chrNew = new char[cnt+10];
 int k = 0;

 for (int i=0;i<10;i++)
 {
/*  cout<  cnt +=out[i].length();
  recInfo[i].chNum = (char)(sizeof(out[i]));
  recInfo[i].path = out[i];
*/
/*  cnt = out[i].length();
  recInfo[i].chNum = (char)*&cnt;
  recInfo[i].path = out[i];
  cout<

你可能感兴趣的:(error C2501: 'string' : missing storage-class or type specifiers)