Salut
Je n’arrive pas à utiliser le type string dans mon projet

Je modifie mon implémentation d’un algorithme pour qu’il utilise le type string au lieu du char* (avec le char* il fonctionnai normalement)

voici le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// project_header.h
#include<string>
class Blowfish
{
      private:
      int var1, var2;
 
      public:
      void f1(string);
      void Cypher(string, string);
      void Decypher(string, string);
};
 
//***************************************************
 
// clacc.cpp
#include"project_header.h"
#include<string>
 
void Blowfish::f1(string PswString){
     unsigned char PswSize=PswString.length();
     char * Psw=PswString.data();
     // etc...
}
 
void Blowfish::Cypher(string StrOne, string StrTwo){
   char * SrcName=StrOne.data();
   char * DestName=StrTwo.data();
   // etc...
}
 
void Blowfish::Decypher(string StrOne, string StrTwo){
   char * SrcName=StrOne.data();
   char * DestName=StrTwo.data();
   // etc..
}
 
//***************************************************
 
// main.cpp
#include<string>
#include <iostream>
#include"project_header.h"
 
int main()
{
    string a;
    Blowfish Raghda;
    Raghda.f1("aa");
    Raghda.Cypher("c:\\a.txt", "c:\\b.txt");
    Raghda.Decypher("c:\\b.txt", "c:\\c.txt");
 
    system("pause");
}
Mais maintenant que j’ai modifier les paramètre des fonction membre de la classe pour qu’ils utilisent le string, à la compilation il me rapporte plusieurs erreurs :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
projetc_header.h  line 9   'string' has not been declared
projetc_header.h  line 9   ISO C++ forbids declaration of 'parameter' with no type
projetc_header.h  line 10  'string' has not been declared
projetc_header.h  line 10  'string' has not been declared
projetc_header.h  line 10  ISO C++ forbids declaration of 'parameter' with no type
projetc_header.h  line 10  ISO C++ forbids declaration of 'parameter' with no type
projetc_header.h  line 11  'string' has not been declared
projetc_header.h  line 11  'string' has not been declared
projetc_header.h  line 11  ISO C++ forbids declaration of 'parameter' with no type
projetc_header.h  line 11  ISO C++ forbids declaration of 'parameter' with no type
 
main.cpp          line 9   'string' undeclared (first use this function)
main.cpp          line 9   (each indeclared identifier is reported only once dor each function it appears in)
main.cpp          line 9   expected ';' before "a"
main.cpp          line 11  invalid conversion from 'const char*' to 'int'
main.cpp          line 11    initializing argument 1 of 'void Blowfish;;f1(int)'
...
je ne peus donc pas utilisez le string comme le char ou int?