当我显然在上面声明时,我在 main.cpp 上遇到了重做字符(粗体)错误。我也想知道为什么它要求我在 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');
}
为什么它声明它但给出一个没有声明的错误真的很令人困惑。