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

关于C++的一个有关问题。 到底哪里出了有关问题?

2012-09-05 
关于C++的一个问题。 到底哪里出了问题???!!//头文件#ifndef _NUMBERS_#define _NUMBERS_#include iostrea

关于C++的一个问题。 到底哪里出了问题???!!

//头文件
#ifndef _NUMBERS_
#define _NUMBERS_

#include <iostream>
#include <string>

using namespace std; 

void calculat(int &letter,int &symbol,int &blank,string &sentence); //声明统计句子中字母,标点,空格键的函数

 void showTheResult(int &letter,int &symbol,int &blank);//显示结果

#endif

/////////////////////////////////////////////////////////////


// 统计字母,符号,空白的数目-string 流.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "function.h"
using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{string sentence;//用来存储字符串
int letter,symbol,blank; //用来存储计算结果
string answer ;//标签
do
  {
cout<<"\n This program will calculate the numbers of letter ,symbol,blank in a sentence .";


cout<<"\n Please enter a sentence here : ";
getline(cin,sentence);

calculat(letter,symbol,blank,sentence);//开始统计 字母,标点,空格的数目 总是这里报错

showTheResult(letter,symbol,blank);//显示结果

cout<<"\n Do you want to try again ? yes/no ==> ";
getline(cin,answer);
   
}while(answer=="yes");

  return 0;
}


//以下是头文件函数的定义


//function 文件
#include <iostream>
#include <string>
using namespace std;
 
void calculat(int &letter,int &symbol,int &blank,string &sentence) //通过ASCII 表选择
 {
int i;
for(i=0;i<sentence.size();i++)
{

if(sentence.at(i)=='a'||sentence.at(i)=='e'||sentence.at(i)=='i'||sentence.at(i)=='o'||sentence.at(i)=='u'||
sentence.at(i)=='A'||sentence.at(i)=='E'||sentence.at(i)=='I'||sentence.at(i)=='O'||sentence.at(i)=='U')
letter++;
else if(sentence.at(i)==' ') 
blank++;
else if ((sentence.at(i)>33&&sentence.at(i)<47)||(sentence.at(i)>58&&sentence.at(i)<63))
symbol++;
}
 }
 
 
 
 
 void showTheResult(int &letter,int &symbol,int &blank)//定义 输出函数
{
cout<<"\n Here is the result :"<<endl;
cout<<"letter : "<<letter<<"symbol : "<<symbol<<"blank : "<<blank<<endl;

}

///////////////以下是错误提示

function.h(9): error C3872: “0x3000”: 此字符不允许在标识符中使用
 语法错误:“void”的前面应有“;”
 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1> function.cpp
 “#include <iostream>”: 在查找预编译头使用时跳过
1> 将指令添加到“StdAfx.h”或重新生成预编译头
 “#include <string>”: 在查找预编译头使用时跳过
1> 将指令添加到“StdAfx.h”或重新生成预编译头
1> fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?
1> 正在生成代码...
1>
1>生成失败。

///使用的编译器是visual studio 2010


[解决办法]
代码是Copy过来的,你自己把有问题的地方,重写书写一下。
[解决办法]

C/C++ code
//function 文件#include "stdafx.h"//添加这个预编译头文件名//还要添加你的函数声明的那个头文件名#include "...h",我这不知道你的那个文件的名字是声明,你添加进去就ok了。#include <iostream>#include <string> 

热点排行