打印

编译问题

[复制链接]
1371|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
txcy|  楼主 | 2012-4-27 20:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#ifndef  __SPLIT_H_
#define  __SPLIT_H_
#endif
//__SPLIT_H_
void StringSplit(string s,char splitchar,vector<string>& vec)
{
   
if(vec.size()>0)//保证vec是空的
        vec.clear();
   
int length = s.length();
   
int start=0;
   
for(int i=0;i<length;i++)
    {
        
if(s == splitchar && i ==
0)//第一个就遇到分割符
        {      
            start
+=
1;
        }      
        
else
if(s == splitchar)
        {      
            vec.push_back(s.substr(start,i
- start));
            start
= i+1;
        }      
        
else
if(i == length-1)//到达尾部
        {
            vec.push_back(s.substr(start,i
+1
- start));
        }
    }
}

报错内容

In file included from a.cpp:24:
split.h:23: error: variable or field `StringSplit' declared void
split.h:23: error: `string' was not declared in this scope
split.h:23: error: expected primary-expression before "char"
split.h:23: error: `vector' was not declared in this scope
split.h:23: error: `string' was not declared in this scope
split.h:23: error: `vec' was not declared in this scope
split.h:24: error: initializer expression list treated as compound expression
split.h:24: error: expected `,' or `;' before '{' token

相关帖子

沙发
火箭球迷| | 2012-4-27 20:45 | 只看该作者
需要包含头文件.
所以要加上下面的:  
#include<vector>
#include<string>
using namespace std;

使用特权

评论回复
板凳
yybj| | 2012-4-27 20:46 | 只看该作者
遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

274

主题

2106

帖子

0

粉丝