gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:20:53 24 4
gpt4 key购买 nike

当我在上面明确声明时,我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com