c++ - Redo char 未声明但已声明

标签 c++ visual-studio-2010

当我在上面明确声明时,我在 main.cpp 上遇到 redo char(粗体)错误。我还想知道为什么它要求我在 using namespace std 前面放一个分号,因为我以前从未这样做过。

//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');
}

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

最佳答案

redo 在循环中声明为局部变量。它的范围从声明点开始,到 while 关键字之前的右大括号结束。名称 redowhile 条件中未知。

关于c++ - Redo char 未声明但已声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19484084/

相关文章:

c++ - 如何修复 Visual Studio 2015 中的错误 MSVCP120D.dll?

c++ - 修改 Boost Python 包装类?

c# - 如何跳过里面有lambda代码的函数?

c# - 使用 savefileDialog 选择文件夹路径

.net - 使用/CLR选项时如何指定.NET版本

c - 第一次机会异常 : KernelBase. dll

c++ - 查找特定区间内的素数

c++ - 加速字节模式扫描 C++

c# - 重载时为什么不考虑函数的返回类型?

c++ vs2010 增加堆栈大小