从另一个.cpp文件启动.cpp文件
Start a .cpp file from another .cpp file
我已经在谷歌和Duckduckgo上尝试了所有内容。 我只是放弃了,来找你问一个问题。
我正在做一个学习CPP的项目,遇到了一个问题。我有 2 个文件。
一个叫:Nudle.cpp(主要的(
// Nudle.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <fstream>
#include <iostream>
#include "PasGen.cpp"
#include "PasGen.h"
using namespace std;
int main(int argc, char* argv[])
{
int choice;
do {
cout << "NUDLE Menun";
cout << "Please make your selectionn";
cout << " 1 - Generate passwordn";
cout << " 2 - View Saved Passwordsn";
cout << " 3 - Quitn";
cout << "Selection = ";
cin >> choice;
switch (choice) {
case 1:
break;
case 2:
cout << "????n";
break;
case 3:
cout << "Goodbye!";
break;
default:
cout << endl << endl << "Main Menun";
cout << "Please make your selectionn";
cout << " 1 - Start gamen";
cout << " 2 - Optionsn";
cout << " 3 - Quitn";
cout << "Selection = ";
cin >> choice;
}
} while (choice != 3);
return EXIT_SUCCESS;
还有一个叫做PasGen.cpp(密码生成器(
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
static const char alphnum[] = "0123456789" "!@#$%^&*" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz";
int strLen = sizeof(alphnum) - 1;
char GenRand()
{
return alphnum[rand() % strLen];
}
int PassGen()
{
int n, c = 0, s = 0;
srand(time(0));
cout << "Enter the length of the password required:";
cin >> n;
cout << n << endl;
cout << "Your Password is:";
N:
char C;
string D;
for (int z = 0; z < n; z++)
{
C = GenRand();
D += C;
if (isdigit(C))
{
c++;
}
if (C == '!' || C == '@' || C == '$' || C == '%' || C == '^' || C == '&' || C == '*' || C == '#')
{
s++;
}
}
if (n > 2 && (s == 0 || c == 0))
{
goto N;
}
cout << D;
}
我只是不知道如何在一个人请求密码生成器
我希望它将输出显示到同一控制台,而不是打开一个新控制台。
管理员请不要关闭我的线程,如果它已经存在。 我几乎都是踩踏,仍然无法理解
您的主.cpp文件中存在一些问题。最大的一个是您将 cpp 文件包含在另一个 cpp 文件中。这通常应该如何工作,分别编译两个 cpp 文件,然后将它们链接在一起以创建最终输出。
所以我注释掉了以下内容(通过添加前导//(
#include "PasGen.cpp"
然后我必须包含 cstdlib,因为您正在使用EXIT_SUCCESS
#include <cstdlib>
最后,我可以在您的案例中调用该函数 1
case 1:
PassGen();
break;
在所有这些更改之后,我可以分别编译这两个文件并将它们链接在一起
g++ -c main.cpp
g++ -c PasGen.cpp
g++ main.o PasGen.o
然后运行它
$ ./a.exe
NUDLE Menu
Please make your selection
1 - Generate password
2 - View Saved Passwords
3 - Quit
Selection = 1
Enter the length of the password required:10
10
Your Password is:N0sJ%YphnFNUDLE Menu
您也可以同时编译这两个文件
g++ main.cpp PasGen.cpp
这最终会做同样的事情,但最好从一开始就直接拥有概念。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 命名空间中具有.h和.cpp文件的类
- 为什么我的主文件.cpp不打印头文件中的任何内容
- 生成文件错误 - 找不到文件 - *.cpp
- 如何在文件.cpp gtkmm中声明小部件
- 没有实现文件(.cpp)的派生类
- 如何使用"CMakeLists.txt"中的add_library将整个文件(.cpp,.h等)包含在目录中
- 如何在Linux / Windows操作系统上使用文件*.cpp一步编译下面的代码
- 关于 Linux .so 文件无法链接到主文件.cpp文件
- 文件.cpp从Windows到Linux
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- 如何将文件.cpp编译为本机编译
- 使用模板类时,似乎无法包含除 main 以外的任何 cpp 文件.cpp
- 无法编译C++文件.cpp。C++98模式
- 为什么C++头文件不需要包含实现文件 (.cpp)
- 如何访问位于独立文件(.cpp)中的非成员函数
- 如何在Visual Studio Code中通过键盘快捷键切换头文件/cpp文件
- 如何将数据从stringstream写入文件(CPP)
- 为什么filestream不把空白写入文件cpp ?