首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redo char未声明,但已声明。

Redo char未声明,但已声明。
EN

Stack Overflow用户
提问于 2013-10-20 23:26:38
回答 2查看 152关注 0票数 0

显然,当我在上面声明时,main.cpp上的重做字符(粗体)出现了错误。我还想知道为什么它要求我在使用命名空间std之前放置分号,因为我以前从未这样做过。

代码语言:javascript
复制
//ReverseString.h
#include <iostream>
#include <string>

using namespace std;

class StringClass
{
public:
string string;
int GetStringLength (char*);
void Reverse(char*);
void OutputString(char*);
void UserInputString (char*);
StringClass();
private:
    int Length;
}

//StringClass.cpp
#include <iostream>
#include <string>
#include "ReverseString.h"

;using namespace std;

void StringClass::UserInputString(char *string)
{
cout << "Input a string you would like to be reversed.\n";
cin >> string;
cout << "The string you entered: " << string << endl;
}
int StringClass::GetStringLength (char *string)
{
Length = strlen(string);
return Length;
}
void StringClass::Reverse(char *string) 
{
 int c;
 char *front, *rear, temp;

 front = string;
 rear = string;

 GetStringLength(string);

 for ( c = 0 ; c < ( Length - 1 ) ; c++ )
  rear++;

 for ( c = 0 ; c < Length/2 ; c++ ) 
 {        
  temp = *rear;
  *rear = *front;
  *front = temp;

  front++;
  rear--;
 }
} 
void StringClass::OutputString(char *string)
{
cout << "Your string reversed is: " << string << ".";
}

//Main.cpp
#include <iostream>
#include <string>
#include <fstream>
#include "ReverseString.h"

;using namespace std;

const int MaxSize = 100;

int main()
{
do
{
    char string[MaxSize];
    **char redo;**

    StringClass str;

    str.UserInputString(string);

    str.Reverse(string);

    str.OutputString(string);

    //Asks user if they want redo the program
    cout << "Would you like to redo the program?\n";
    cout << "Please enter Y or N: \n";
    **cin >> redo;**
}while(redo == 'Y' || redo == 'y');
}

它为什么声明它,但是给出了一个没有声明的错误,这真是令人困惑。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-20 23:29:53

redo被声明为循环中的局部变量。它的作用域从声明点开始,在while关键字前面的结束大括号结束。在redo条件中不知道名称while

票数 1
EN

Stack Overflow用户

发布于 2013-10-20 23:29:49

ReverseString.h中的类声明之后,您缺少了一个分号。

编译器在using namespace std;行上获取错误,因为这是第一次检测到问题的时候。这并不意味着你应该把分号放在那里。

一些编译器会提示您可能在类声明中缺少分号,而其他编译器则不会。这个错误是很常见的。如果您在一个可笑的地方看到丢失的分号错误,您应该立即考虑到您可能不小心把一个从标题中遗漏了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19484084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档