Stupid C++ question...

Put your programming skills to the test in these challenges.

Re: Stupid C++ question...

Post by Kamman on Thu Aug 21, 2008 2:57 am
([msg=10171]see Re: Stupid C++ question...[/msg])

PaCkEtPiRaTe wrote: string password += characters[rand()%characters_len];


You are using 2 String Password declarations ...

remove the second one within the braces.. it should work
Kamman
New User
New User
 
Posts: 2
Joined: Thu Aug 21, 2008 2:54 am
Blog: View Blog (0)


Re: Stupid C++ question...

Post by Kamman on Thu Aug 21, 2008 3:00 am
([msg=10172]see Re: Stupid C++ question...[/msg])

[quote="PaCkEtPiRaTe"]It's not working... here's the code now...

Code: Select all

// Random Password Generator by ----------------------.
// Copyright © 2008-2013. All rights reserved.
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
using namespace std;

int main() {
    srand(time(NULL));
    int pass_Length = 0;
    char characters [] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\0' };
    int characters_len = sizeof(characters) / sizeof(char);
    string password;
   
    while (pass_Length < 20) {
          string password += characters[rand()%characters_len];
          pass_Length++;
          }
    ofstream fout("password.txt");
    fout << "The password generated was: " << password << "\n";
    fout << flush;
    fout.close();
    cout << endl;
    system("PAUSE");
    return 0;
}



And the compiler is giving me these errors...

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Users\PaCkEtPiRaTe\Documents\password_generator.cpp" -o "C:\Users\PaCkEtPiRaTe\Documents\password_generator.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/fstream.h:31,
from C:\Users\PaCkEtPiRaTe\Documents\password_generator.cpp:4:
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
C:\Users\PaCkEtPiRaTe\Documents\password_generator.cpp: In function `int main()':
C:\Users\PaCkEtPiRaTe\Documents\password_generator.cpp:16: error: expected primary-expression before "password"
C:\Users\PaCkEtPiRaTe\Documents\password_generator.cpp:16: error: expected `;' before "password"

Execution terminated

It will run, but it won't write the file.


It wont write the file becoz you have 2 string declarations.. try to remove the one within the loop, it should work !
Kamman
New User
New User
 
Posts: 2
Joined: Thu Aug 21, 2008 2:54 am
Blog: View Blog (0)


Re: Stupid C++ question...

Post by PaCkEtPiRaTe on Thu Aug 21, 2008 10:55 am
([msg=10193]see Re: Stupid C++ question...[/msg])

AbaxHacker wrote:You either were using a clr console and it didn't work or a windows, vice versa or you had no pre-compiled header this time.


I have no idea what that means, heh...
PaCkEtPiRaTe
New User
New User
 
Posts: 9
Joined: Tue Aug 19, 2008 9:30 pm
Blog: View Blog (0)


Re: Stupid C++ question...

Post by PaCkEtPiRaTe on Thu Aug 21, 2008 2:00 pm
([msg=10201]see Re: Stupid C++ question...[/msg])

HOORAY, IT WORKS!
PaCkEtPiRaTe
New User
New User
 
Posts: 9
Joined: Tue Aug 19, 2008 9:30 pm
Blog: View Blog (0)


Re: Stupid C++ question...

Post by AbaxHacker on Thu Aug 21, 2008 6:34 pm
([msg=10217]see Re: Stupid C++ question...[/msg])

Just noticed your declaring the string inside the loop, but before this post, silly me.
AbaxHacker
New User
New User
 
Posts: 17
Joined: Tue Aug 19, 2008 6:31 pm
Blog: View Blog (0)


Re: Stupid C++ question...

Post by mosshack on Sat Aug 30, 2008 11:47 am
([msg=10668]see Re: Stupid C++ question...[/msg])

To add it to a text file i would suggest storing it within a array or what ever it is ( Im tired xD) then putting that array into the text file. I am a n00b in C++ and dont have a clue about it but if i was to code it within any other language i know i would use that form
mosshack
New User
New User
 
Posts: 18
Joined: Wed Apr 30, 2008 4:59 pm
Blog: View Blog (0)


Previous

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests