I've created a list of strings and load a text file in it. once list is created, the program have to read it, do something and write results in a new text file. [CODE] ofstream f; f.open("filename.txt"); string key; list<string> text; static char ALPH[21] = {'A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z'}; int* index_t = new int[text.size()]; int* index_k = new int[key.length()]; for(int i = 0; i < key.length(); i++){ for(int j = 0; j < 21; j++){ if(key[i] == ALPH[j]) index_k[i] = j; } } for(list<string>::iterator it = text.begin(); it != text.end(); it++){ for(int i = 0; i < it->length(); i++){ for(int j = 0; …

Member Avatar
Member Avatar
+0 forum 3

I wrote a program that creates a text file with some letters using ofstream. Now I would like to format the text so that the letters are written in groups of 5 and the rows are all the same length( i.e. DANIWEBFORUM becomes DANIW EBFOR UM). To do this the fprintf function seemed the most appropriate. in the following example I use integers, but it is just an example. [CODE] #include <string> #include <iomanip> #include <fstream> #include <cstdio> using namespace std; int main() { ofstream f; f.open("testo.txt"); for(int i = 0; i < 21; i++) { f << i; } …

Member Avatar
Member Avatar
+0 forum 1

I have to write an application in which a text file is read and stored in a vector of strings [CODE]vector<string> text;[/CODE] After that I have to compare each character of text loaded from a file with an array of char with default content [CODE]char ARRAY[21] = {... ... ...}[/CODE] so I thought something like that [CODE] for(int i = 0; i < text.size(); i++){ for(int j = 0; j < 21; j++){ if(text[i] == ARRAY[j]) index_t[i] = j; } } [/CODE] at compile time I get the following error: no match for 'operator==' in '(((std::vector<std::string, std::allocator<std::string> >*) how can …

Member Avatar
Member Avatar
+0 forum 4

the program must read a text file, encrypt the content and then rewrite everything to a text file. compile ok, it crashes while running and still produces an empty output. how can I fix this? vigenere.h [CODE] #include <string> using namespace std; class Vigenere{ private: string key; string text; static char ALPH[21]; static string StringToUpper(string); void LoadText(string); static string EraseChar(string); void TextErase(); public: Vigenere(string); void encode(string, string); void decode(string, string); }; [/CODE]vigenere.cpp [CODE] #include "vigenere.h" #include <string> #include <iostream> #include <fstream> using namespace std; //genera la chiave Vigenere::Vigenere(string str){ key = str; key = StringToUpper(key); if(!key.empty()){ key = EraseChar(key); } …

Member Avatar
Member Avatar
+0 forum 2

I have to write an application which uses the Vigenere cipher with the Italian alphabet (only 21 characters, excluded J,K,W,X,Y). After a day of trying this is the code that I wrote [CODE] #include "vigenere.h" #include <string> using namespace std; Vigenere::Vigenere(string str){ key = str; key = StringToUpper(key); for(int cnt = 0; cnt < key.length(); cnt++){ if(key[cnt] < 'A' || key[cnt] > 'Z') key.erase(cnt,1); } //nel caso in cui la chiave sia piĆ¹ corta del testo for(int cnt = 0; cnt < text.length(); cnt++){ if(key.length() != text.length()){ if(key.length() < text.length()) key += key[cnt]; } } return; } //tavola di Vigenere …

Member Avatar
Member Avatar
+0 forum 10

can someone tell me how this program works? I'm trying to learning C++ by reading some examples, and this one is one of them. [CODE]#include <iostream> #include <string> using namespace std; class Vigenere { public: string key; Vigenere(string key) { for(int i = 0; i < key.size(); ++i) { if(key[i] >= 'A' && key[i] <= 'Z') this->key += key[i]; else if(key[i] >= 'a' && key[i] <= 'z') this->key += key[i] + 'A' - 'a'; } } string encrypt(string text) { string out; for(int i = 0, j = 0; i < text.length(); ++i) { char c = text[i]; if(c >= …

Member Avatar
Member Avatar
-1 forum 4

The End.