Error strcpy was not declared in this scope

Ubuntu 14.04 LTS gcc 4.9 In file included from /home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp:25:0, from /home/ren/Compile/CGAL/cgal/build/Debug/Installation/src/CGAL_ImageIO...
In file included from /home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp:25:0,
                 from /home/ren/Compile/CGAL/cgal/build/Debug/Installation/src/CGAL_ImageIO/all_files.cpp:1:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h: In function ‘imformat* createAnalyzeFormat()’:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:201:54: error: ‘strcpy’ was not declared in this scope
   strcpy(f->fileExtension,".hdr,.hdr.gz,.img,.img.gz");
                                                      ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h: In function ‘int testAnalyzeHeader(char*, const char*)’:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:209:39: error: ‘memcmp’ was not declared in this scope
   if( !memcmp(magic,ANALYZE_LE_MAGIC,4) ||
                                       ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h: In function ‘int writeAnalyze(char*, _image*)’:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:222:21: error: ‘strlen’ was not declared in this scope
   length=strlen(name);
                     ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:225:42: error: ‘strncmp’ was not declared in this scope
   if ( strncmp( name+length-4, ".hdr", 4 ) == 0 ) {
                                          ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:238:47: error: ‘strncpy’ was not declared in this scope
   strncpy( outputName, name, length-extLength );
                                               ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:239:45: error: ‘strncmp’ was not declared in this scope
   if ( strncmp( name+length-7, ".hdr.gz", 7 ) == 0 )
                                             ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:240:52: error: ‘strcpy’ was not declared in this scope
     strcpy( outputName+length-extLength, ".hdr.gz" );
                                                    ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:242:49: error: ‘strcpy’ was not declared in this scope
     strcpy( outputName+length-extLength, ".hdr" );
                                                 ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:265:41: error: ‘strncmp’ was not declared in this scope
   if ( strncmp( name+length-3, ".gz", 3 ) == 0 ) {
                                         ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:266:52: error: ‘strcpy’ was not declared in this scope
     strcpy( outputName+length-extLength, ".img.gz" );
                                                    ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:269:49: error: ‘strcpy’ was not declared in this scope
     strcpy( outputName+length-extLength, ".img" );
                                                 ^
In file included from /home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze.cpp:25:0,
                 from /home/ren/Compile/CGAL/cgal/build/Debug/Installation/src/CGAL_ImageIO/all_files.cpp:1:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h: In function ‘int _readAnalyzeHeader(_image*, const char*, dsr*)’:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:470:101: error: ‘strlen’ was not declared in this scope
       im->user[i] = (char *) ImageIO_alloc((strlen("Data lost in the Analyze -> ImageIO conversion:") + 1));
                                                                                                     ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:532:36: error: ‘strcmp’ was not declared in this scope
  if( strcmp( name+length-4, ".hdr" ) )
                                    ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:542:27: error: ‘strcpy’ was not declared in this scope
  strcpy(data_filename,name);
                           ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h: In function ‘int writeAnalyzeHeader(const _image*)’:
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:598:37: error: ‘memset’ was not declared in this scope
    memset(&hdr,0, sizeof(struct dsr));
                                     ^
/home/ren/Compile/CGAL/cgal/CGAL_ImageIO/src/CGAL_ImageIO/analyze_impl.h:763:36: error: ‘strcpy’ was not declared in this scope
     strcpy(hdr.dime.vox_units,"mm.");
                                    ^
make[2]: *** [Installation/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/all_files.cpp.o] Error 1
make[1]: *** [Installation/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/all] Error 2

Rukov

5 / 5 / 0

Регистрация: 24.01.2017

Сообщений: 223

1

02.08.2017, 17:56. Показов 4854. Ответов 7

Метки нет (Все метки)


код с учебника но выдает ошибку…
библиотеки подключены…в чем причина может быть ?

C
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <string.h>
 
class MyCar
{
                    private: char name[50];
                private: int speed;
                private: char owner_name[50];
        
    public:char n[50];
    public: int s;
    public:char on[50];
    
    //Конструктор класса 1
    public: MyCar(char Name[50], int Speed, char Owner_name[50])
    {
        strspy_s(name, Name); //?      здесь выдает ошибку  [Error] 'strspy_s' was not declared in this scope
             name[strlen(Name)]='';
        speed = Speed;
        strspy_s(owner_name, Owner_name); //?
        
        owner_name[strlen(Owner_name)]='';
    }
    
    //Конструктор класса 2
    public: MyCar (char Name[50],int Speed)
    {
        strspy_s(name,Name);//?
        name[strlen(Name)]='';
        speed=Speed;
    }
 
    // Метод1 класса
    public: int M1(){
        speed = speed*2;
    }
    // Метод2 класса
    public: int M2(){
      strspy(n,name);//?
      n[strlen(name)]='';
      s=speed;
      strspy_s(on, owner_name);//?
      on[strlen(owner_name)]='';
      return(0);
    }
    
    // Метод3 класса
    public: int M3(){
      strspy_s(n, name);//?
      n[strlen(name)]='';
      s=speed;
      return(0);
      
    }
    
};  //class
 
int main(){
 
    MyCar *car = (MyCar*) new MyCar("Wolwo",120,"Иванов");
    car->M1();
    car->M3();
 
   printf("object1:car->name = %s, speed = %dn",car->n,car->s);
    car = new MyCar("Wolwo",120);
    car->M1();
    car->M3();
    printf("object2:car->name = %s, speed = %dn",car->n,car->s);
    
    _getch();
 
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Mental handicap

1245 / 623 / 171

Регистрация: 24.11.2015

Сообщений: 2,429

02.08.2017, 18:31

2

Цитата
Сообщение от Rukov
Посмотреть сообщение

strspy_s

ем.. может вместо strspy_s (эта команда, что должна следить за стрококй, скрытно, или как?) должно быть strcpy_s ?
И вообще, код написан на Си, а раздел для С++, пишите в соответсвующий раздел!



0



5 / 5 / 0

Регистрация: 24.01.2017

Сообщений: 223

02.08.2017, 18:42

 [ТС]

3

Цитата
Сообщение от Azazel-San
Посмотреть сообщение

ем.. может вместо strspy_s (эта команда, что должна следить за стрококй, скрытно, или как?) должно быть strcpy_s ?

это функция копирования строка строку



0



Mental handicap

1245 / 623 / 171

Регистрация: 24.11.2015

Сообщений: 2,429

02.08.2017, 18:47

4

Цитата
Сообщение от Rukov
Посмотреть сообщение

это функция копирования строка строку

функция копирования строки в строку наз. strcpy через c, а не s. Если расшифровать, то будет

string copy

( с анг. строка копировать, если дословно)



0



5 / 5 / 0

Регистрация: 24.01.2017

Сообщений: 223

02.08.2017, 18:58

 [ТС]

5

то же самое после исправления…
38 21 C:…….Class_001.cpp [Error] ‘strcpy_s’ was not declared in this scope



0



Модератор

Эксперт PythonЭксперт JavaЭксперт CЭксперт С++

11659 / 7172 / 1704

Регистрация: 25.07.2009

Сообщений: 13,142

02.08.2017, 19:14

6

Цитата
Сообщение от Rukov
Посмотреть сообщение

strcpy_s

Это не стандартная функция а костыль, придуманный мелкомягкими разработчиками. В книжке наверняка написано, что примеры в какой-нибудь из мелкостудий проверялись…



1



5 / 5 / 0

Регистрация: 24.01.2017

Сообщений: 223

02.08.2017, 19:35

 [ТС]

7

«Пахомов С/С++ 2 издание MS VC++ 2012 (для начинающих)» стр. 147
******

заменил на strncpy….проходит



0



Форумчанин

Эксперт CЭксперт С++

8193 / 5043 / 1437

Регистрация: 29.11.2010

Сообщений: 13,453

03.08.2017, 13:57

8

strncpy достаточно коварен, лучше его не использовать. Да и вообще, в С++ есть замечательный std::string, где копирование и конкатенация представлены в виде операторов.
Распространенные ошибки



0



Posted By: Anonymous

I get this problem in a c++ problem compiling in Ubuntu g++ version 4.4.3.
I dont know the headers to include to solve this problem.. Thanks

centro_medico.cpp: In constructor ‘Centro_medico::Centro_medico(char*, char*, int, int, float)’:
centro_medico.cpp:5: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘Centro_medico& Centro_medico::operator=(const Centro_medico&)’:
centro_medico.cpp:26: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘bool Centro_medico::quitar_medico(int)’:
centro_medico.cpp:92: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:92: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘void Centro_medico::mostrar_especialidades(std::ostream&) const’:
centro_medico.cpp:123: error: ‘strcmpi’ was not declared in this scope
centro_medico.cpp: In member function ‘void Centro_medico::mostrar_horarios_consulta(char*) const’:
centro_medico.cpp:162: error: ‘strcmpi’ was not declared in this scope
centro_medico.cpp: In member function ‘void Centro_medico::crea_medicos()’:
centro_medico.cpp:321: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:321: warning: deprecated conversion from string constant to ‘char*’

medico.cpp

#include "medico.h"
#include <cstdlib>
#include <iostream>
#include <stdlib>  
#include<cstring>
#include<string>

long Medico::total_consultas=0; 
Medico::Medico(char *nom,char * espe,int colegiado,int trabajo)
{
int i;
strcpy(nombre,nom);
strcpy(especialidad,espe);
num_colegiado=colegiado;
num_horas_diarias=trabajo;
citas_medico= new Cita*[5]; // 5 Días de las semana, de Lunes a Viernes.
for (i=0;i<5;i++)
citas_medico[i]=new Cita[num_horas_diarias];
}



Medico::Medico(const Medico &m){
  int i;
  citas_medico=new Cita*[5];
  for (i=0;i<5;i++)
   citas_medico[i]=NULL;
 (*this) = m;
}

Medico &Medico::operator=(const Medico &m){
 int i,j;
 if (this != &m) { // Para evitar la asignación de un objeto a sí mismo
     strcpy(nombre,m.nombre);
     strcpy(especialidad,m.especialidad);     
     num_colegiado=m.num_colegiado;
     num_horas_diarias=m.num_horas_diarias;
     for (i=0;i<5;i++){
      delete citas_medico[i]; 
      citas_medico[i]=new Cita[num_horas_diarias];
      for(j=0;j<num_horas_diarias;j++){
       citas_medico[i][j] = m.citas_medico[i][j] ;
       }
     }     
  }
 return *this;
}

medico.h

#pragma once
#include <cstdlib>
#include <iostream>
using namespace std;
#include "cita.h"

class Medico
{
 private:
                char nombre[50];
                char especialidad[50];
                int num_colegiado;
                int num_horas_diarias;
                Cita **citas_medico;
                static long total_consultas;                
 public:
                void mostrar_calendario_citas(ostream &o=cout) const;
                bool asignar_cita(int d, int hor,Paciente *p=NULL);
                void anular_cita(int d, int hor);
                bool consultar_cita(char dni[10], int modificar=0);
                void modificar_cita(int d, int hor);                
                void vaciar_calendario_citas();
                void borrar_calendario_citas();                
                char* get_especialidad(char espec[50]) const;
                char* get_nombre(char n[50]) const;
                int get_num_colegiado() const;
                int get_num_horas() const;
                void set_num_horas(int horas);
                void mostrar_info(ostream &o=cout) const;
                static long get_total_consultas();
                Cita* operator[](int dia);
                void eliminar_calendario_citas();
                void crear_calendario_citas();    
                Medico(char *nom,char * espe,int colegiado,int trabajo);
                Medico(const Medico &m);
                Medico &operator=(const Medico &c);
                void operator delete(void*);
                ~Medico();
 };
 ostream& operator<<(ostream &o, Medico &c);
 ofstream& operator<<(ofstream &fichero, Medico &m);
 ifstream& operator>>(ifstream &fichero, Medico &m);

Solution

Observations:

  • #include <cstring> should introduce std::strcpy().
  • using namespace std; (as written in medico.h) introduces any identifiers from std:: into the global namespace.

Aside from using namespace std; being somewhat clumsy once the application grows larger (as it introduces one hell of a lot of identifiers into the global namespace), and that you should never use using in a header file (see below!), using namespace does not affect identifiers introduced after the statement.

(using namespace std is written in the header, which is included in medico.cpp, but #include <cstring> comes after that.)

My advice: Put the using namespace std; (if you insist on using it at all) into medico.cpp, after any includes, and use explicit std:: in medico.h.


strcmpi() is not a standard function at all; while being defined on Windows, you have to solve case-insensitive compares differently on Linux.

(On general terms, I would like to point to this answer with regards to «proper» string handling in C and C++ that takes Unicode into account, as every application should. Summary: The standard cannot handle these things correctly; do use ICU.)


warning: deprecated conversion from string constant to ‘char*’

A «string constant» is when you write a string literal (e.g. "Hello") in your code. Its type is const char[], i.e. array of constant characters (as you cannot change the characters). You can assign an array to a pointer, but assigning to char *, i.e. removing the const qualifier, generates the warning you are seeing.


OT clarification: using in a header file changes visibility of identifiers for anyone including that header, which is usually not what the user of your header file wants. For example, I could use std::string and a self-written ::string just perfectly in my code, unless I include your medico.h, because then the two classes will clash.

Don’t use using in header files.

And even in implementation files, it can introduce lots of ambiguity. There is a case to be made to use explicit namespacing in implementation files as well.

Answered By: Anonymous

Related Articles

  • Ubuntu apt-get unable to fetch packages
  • C++ template,typename and operator
  • no match for ‘operator
  • Most effective way to parse JSON Objects
  • problem with client server unix domain stream sockets…
  • Callback functions in C++
  • What does this symbol mean in JavaScript?
  • Docker not able to install git on Ubuntu container
  • What are the nuances of scope prototypal / prototypical…
  • What is The Rule of Three?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Observations:

  • #include <cstring> should introduce std::strcpy().
  • using namespace std; (as written in medico.h) introduces any identifiers from std:: into the global namespace.

Aside from using namespace std; being somewhat clumsy once the application grows larger (as it introduces one hell of a lot of identifiers into the global namespace), and that you should never use using in a header file (see below!), using namespace does not affect identifiers introduced after the statement.

(using namespace std is written in the header, which is included in medico.cpp, but #include <cstring> comes after that.)

My advice: Put the using namespace std; (if you insist on using it at all) into medico.cpp, after any includes, and use explicit std:: in medico.h.


strcmpi() is not a standard function at all; while being defined on Windows, you have to solve case-insensitive compares differently on Linux.

(On general terms, I would like to point to this answer with regards to «proper» string handling in C and C++ that takes Unicode into account, as every application should. Summary: The standard cannot handle these things correctly; do use ICU.)


warning: deprecated conversion from string constant to ‘char*’

A «string constant» is when you write a string literal (e.g. "Hello") in your code. Its type is const char[], i.e. array of constant characters (as you cannot change the characters). You can assign an array to a pointer, but assigning to char *, i.e. removing the const qualifier, generates the warning you are seeing.


OT clarification: using in a header file changes visibility of identifiers for anyone including that header, which is usually not what the user of your header file wants. For example, I could use std::string and a self-written ::string just perfectly in my code, unless I include your medico.h, because then the two classes will clash.

Don’t use using in header files.

And even in implementation files, it can introduce lots of ambiguity. There is a case to be made to use explicit namespacing in implementation files as well.

syntax error- ‘strcpy’ was not declared in this scope

Discussion in ‘C’ started by LOG, May 22, 2011.


  1. LOG

    LOG
    New Member

    Joined:
    May 22, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0

    I am getting an error while compiling, saying that strcpy is not declared in the scope. This segment is the definitions for monsters in a text adventure.

    void initializeMonsters()
    {
        // old elk
        monsterArray[0].strength = 10;
        monsterArray[0].dexterity = 10;
        monsterArray[0].hp = 10;
        strcpy(monsterArray[0].name, "Old Elk");
        // Archer
        monsterArray[1].strength = 15;
        monsterArray[1].dexterity = 20;
        monsterArray[1].hp = 15;
        strcpy(monsterArray[0].name, "Archer");
        // Dreadful Skeleton
        monsterArray[2].strength = 20;
        monsterArray[2].dexterity = 10;
        monsterArray[2].hp = 25;
        strcpy(monsterArray[0].name, "Dreadful Skeleton");
        // Ug'lor
        monsterArray[3].strength = 25;
        monsterArray[3].dexterity = 25;
        monsterArray[3].hp = 60;
        strcpy(monsterArray[0].name, "Ug'lor");
        // Graldo >>Fight Before Ga'rados<<
        monsterArray[4].strength = 40;
        monsterArray[4].dexterity = 45;
        monsterArray[4].hp = 60;
        strcpy(monsterArray[0].name, "Graldo");
        // Ga'Rados >>boss<<
        monsterArray[5].strength = 95;
        monsterArray[5].dexterity = 115;
        monsterArray[5].hp = 90;
        strcpy(monsterArray[5].name, "Ga'rados");
    }
    

    The declarations that I made are:

    #include <iostream>
    #include<ctime>
    #include<cstdlib>
    #include<cctype>
    using namespace std;

    I do not understand what I am doing wrong.

    Any help is appreciated.

    Thanks,
    LOG:)


  2. xpi0t0s

    xpi0t0s
    Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:

    England

    You need to #include the header that defines strcpy, which is string.h.

Share This Page


Go4Expert

Понравилась статья? Поделить с друзьями:
  • Error stray start tag html
  • Error stray start tag footer
  • Error status invalid gpt 0xc0030008 как исправить
  • Error status format exception 0xc0050009
  • Error status file not found 0xc001000d