Error cout was not declared in this scope

Ошибка компиляции "count was not declared in this scope" C++ Решение и ответ на вопрос 2809183

Kazumiju

0 / 0 / 0

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

Сообщений: 2

1

05.04.2021, 21:01. Показов 8733. Ответов 6

Метки лаба (Все метки)


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
// Example program
//
#include <iostream>
#include <string>
using namespace std;
int main()
{
char a[40];
char b[3];
char c[10];
char d[50];
int f=0, l=0;
count << "Ваше ФИО"<<endl;//<<-это оператор вывода »-это оператор ввода count «‘выводимая строка’ cin »‘имя переменной’
cin.getline(a,40);
count << "Ваш возраст"<<endl;
cin.getline(b,3);
count << "Ваш пол"<<endl;
cin.getline(c,10);
count << "Ваш адрес"<<endl;
cin.getline(d,50);
count << "Ваше образование"<<endl;
cin >>(f);
count << "Ваш номер телефона"<<endl;
count<<"+7";
cin >>(l);
count << "Ваше ФИО" << a << endl;
count << "Ваш возраст" << b << endl;
count << "Ваш пол" << c << endl;
count << "Ваш адрес" << d << endl;
count << "Ваше образование" << f << endl;
count << "Ваш номер телефона" <<"+7"<< l << endl;
}

Выдает ошибку:
main.cpp: In function ‘int main()’:
main.cpp:13:1: error: ‘count’ was not declared in this scope
count << «Ваше ФИО»<<endl;
^~~~~

мучаюсь уже почти час, никак не пойму что нужно сделать

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



0



1369 / 592 / 199

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

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

05.04.2021, 21:06

2

Лучший ответ Сообщение было отмечено Kazumiju как решение

Решение

Внимательнее быть. Почему count, а не cout?



1



0 / 0 / 0

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

Сообщений: 2

05.04.2021, 21:13

 [ТС]

3

Можете исправить?
потому что я попытался, все равно не вдуплил ;c

Добавлено через 3 минуты
Извиняюсь, можете объяснить подробнее?
или же исправить код



0



1369 / 592 / 199

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

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

05.04.2021, 21:34

4

Что Вам не понятно?
Надо писать не count <<, а cout <<. Вот и поправьте во всех местах.

cout — это объект такой, который умеет выводить информацию на экран. Он описан в

<iostream>, а count что? Вы что не видите, что в одном слове есть буква n, а в другом нет, что в одном слове 4 буквы, а в другом 5?



0



Volga_

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

4259 / 2465 / 1334

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

Сообщений: 4,633

Записей в блоге: 1

05.04.2021, 23:35

5

Лучший ответ Сообщение было отмечено Volga_ как решение

Решение

Kazumiju, переделаю немного:

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
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string name;
    int age;
    string gend;
    string adr;
    int level, numphone;
    cout << "Ваше ФИО: ";
    getline(cin, name);
    cout << "Ваш возраст: ";
    cin >> age;
    cout << "Ваш пол: ";
    cin.ignore();
    getline(cin, gend);
    cout << "Ваш адрес: ";
    getline(cin, adr);
    cout << "Ваше образование: ";
    cin >> level;
    cout << "Ваш номер телефона: +7 ";
    cin >> numphone;
    cout << "Ваше ФИО: " << name << endl;
    cout << "Ваш возраст: " << age << endl;
    cout << "Ваш пол: " << gend << endl;
    cout << "Ваш адрес: " << adr << endl;
    cout << "Ваше образование: " << level << endl;
    cout << "Ваш номер телефона: +7 " << numphone << endl;
    system("pause");
    return 0;
}



1



Yetty

7423 / 5018 / 2890

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

Сообщений: 15,694

05.04.2021, 23:50

6

Volga_, просто интересно. почему Вы решили пол вводить через getline, а телефон через cin ?

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

int level, numphone;

C++
1
2
string level;
string phone_number;



1



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

4259 / 2465 / 1334

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

Сообщений: 4,633

Записей в блоге: 1

06.04.2021, 00:04

7

Yetty, можно такой. Я думаю, что это только пример для изучения Си++ для начинающих. Согласен с вами в практике.



0



I am getting error in this code i in count what to do?i have idea of count and its functionality and its work it is working in the function .but the error is still in insert function can anyone pl explain this.

#include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>   struct node {
        int data;
        struct node *next; }*head;

        void append(int num) {
        struct node *temp,*right;
        temp= (struct node *)malloc(sizeof(struct node));
        temp->data=num;
        right=(struct node *)head;
        while(right->next != NULL)
        right=right->next;
        right->next =temp;
        right=temp;
        right->next=NULL; }

add function

 void add( int num ) {
        struct node *temp;
        temp=(struct node *)malloc(sizeof(struct node));
        temp->data=num;
        if (head== NULL)
        {
        head=temp;
        head->next=NULL;
        }
        else
        {
        temp->next=head;
        head=temp;
        } } void addafter(int num, int loc) {
        int i;
        struct node *temp,*left,*right;
        right=head;
        for(i=1;i<loc;i++)
        {
        left=right;
        right=right->next;
        }
        temp=(struct node *)malloc(sizeof(struct node));
        temp->data=num;
        left->next=temp;
        left=temp;
        left->next=right;
        return; }

This is the function in which i am getting the error can anyone pl explain this?

void insert(int num) {
        int c=0;
        struct node *temp;
        temp=head;
        if(temp==NULL)
        {
        add(num);
        }
        else
    {
    while(temp!=NULL)
    {
        if(temp->data<num)
        c++;
        temp=temp->next;
    }
    if(c==0)
        add(num);

   else if(c < count()) \ 83   23  [Error] 'count' was not declared in this \scope

        addafter(num,++c);
    else
        append(num);
    } }

Delete function

 int delete(int num) {
    struct node *temp, *prev;
    temp=head;
    while(temp!=NULL)
    {
    if(temp->data==num)
    {
        if(temp==head)
        {
        head=temp->next;
        free(temp);
        return 1;
        }
        else
        {
        prev->next=temp->next;
        free(temp);
        return 1;
        }
    }
    else
    {
        prev=temp;
        temp= temp->next;
    }
    }
    return 0; }
    void  display(struct node *r) {
    r=head;
    if(r==NULL)
    {
    return;
    }
    while(r!=NULL)
    {
    printf("%d ",r->data);
    r=r->next;
    }
    printf("n"); }
    int count() {
    struct node *n;
    int c=0;
    n=head;
    while(n!=NULL)
    {
    n=n->next;
    c++;
    }
    return c; }
    int  main() {
    int i,num;
    struct node *n;
        head=NULL;
        while(1)
        {
        printf("nList Operationsn");
        printf("===============n");
        printf("1.Insertn");
        printf("2.Displayn");
        printf("3.Sizen");
        printf("4.Deleten");
        printf("5.Exitn");
        printf("Enter your choice : ");
        if(scanf("%d",&i)<=0){
            printf("Enter only an Integern");
            exit(0);
        } else {
            switch(i)
            {
            case 1:      printf("Enter the number to insert : ");
                     scanf("%d",&num);
                     insert(num);
                     break;
            case 2:     if(head==NULL)
                    {
                    printf("List is Emptyn");
                    }
                    else
                    {
                    printf("Element(s) in the list are : ");
                    }
                    display(n);
                    break;
            case 3:     printf("Size of the list is %dn",count());
                    break;
            case 4:     if(head==NULL)
                    printf("List is Emptyn");
                    else{
                    printf("Enter the number to delete : ");
                    scanf("%d",&num);
                    if(delete(num))
                        printf("%d deleted successfullyn",num);
                    else
                        printf("%d not found in the listn",num);
                    }
                    break;
            case 5:     return 0;
            default:    printf("Invalid optionn");
            }
        }
        }
        return 0; }

  • Forum
  • Beginners
  • «___ was not declared in this scope» err

«___ was not declared in this scope» errors

I am receiving compiler errors as follows and do not know how to fix this. I know it’s the same type of error, I just don’t exactly know how to fix this error. Thanks in advanced!

main.cpp: In function ‘int main()’:
main.cpp:26:18: error: ‘count’ was not declared in this scope
for (count = 1; count <= 12; count ++);
^
main.cpp:28:13: error: ‘count’ was not declared in this scope
count = count + 1;
^
main.cpp:29:13: error: ‘output’ was not declared in this scope
output count;
^

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
#include <iostream>
#include <cstdlib>
#include <string>
    using namespace std;
    int main()
    {
            int acctNum;
            string firstName;
            string lastName;
            int purchasePrice;
            int payment;
           
            
            cout << "Please enter account number";
            cin >> acctNum;
            cout << "Please enter customer's first name";
            cin >> firstName;
            cout << "Please enter purchase price";
            cin >> purchasePrice;
            
            payment = purchasePrice / 12;
            cout << "Customer first name:" << firstName <<endl;
            cout << "Customer last name:" << lastName <<endl;
            cout << "Account number:" << acctNum <<endl;
            
            for (count = 1; count <= 12; count ++);
            cout << "Payment number";
            count = count + 1;
            output count;
    }

Last edited on

You’re getting that error because you hadn’t initialized the ‘count’ variable. Write
int count; after int payment;

Also replace output count with cout<<count;
cout is used for console output. There’s nothing called output in STL of C++

Also:
can you explain what you’re trying to do with this block:

1
2
3
4
            for (count = 1; count <= 12; count ++);
            cout << "Payment number";
            count = count + 1;
            output count;

Last edited on

Hello bkatic,

In addition to what Nwb has said you should give this a read http://www.cplusplus.com/doc/tutorial/control/#for

After yo will notice that for loops are generally written as:

1
2
3
4
for (int count = 1; count <= 12; count++)
{
    // <--- your code here.
}

The «int» allows you to define the variable count for use as a local variable in the for loop.

To what you think is in the for loop. Actually nothing because of the semicolon at the end of line 27 that should not be there. What it does is limit the for loop to just that line.

This is what your code looks line in a different way:

1
2
3
4
5
6
7
for (count = 1; count <= 12; count++);

cout << "Payment number";
	
count = count + 1;
	
output count;

I think this is what you intended:

1
2
3
4
5
6
7
8
for (int count = 1; count <= 12; count++)
{
	cout << "Payment number";

	count = count + 1;

	output count;
}

What is the point of line 5 in the above code? Between this and the for loop you are adding 2 to count on each iteration of the loop. Adding to count is what the third part of the for condition is for.

Hope that helps,

Andy

Wow, thank you for the responses! I finally got it to work. As to what I’m trying to do with the

1
2
3
4
for (count = 1; count <=12; count ++)
cout << "Payment number";
count = count + 1;
cout << count; 

is from the pseudocode my homework assignment gave me. The pseudocode is as follows:

for count 1 to 12
output «Payment Number», count, «: $» , payment.
endfor

For context the assignment is designing an application that accept’s a client’s loan amount and monthly payment amount and outputs the loan balance each month until the loan is paid off.

But after further inspection and your feedback I understand why it doesn’t make sense and I have to switch things around. Thank you again!

So you’re supposed to display
"Payment Number" count ": $" payment
for 12 purchases

( In your for loop you need to add braces like Andy said, but also you don’t need count = count + 1 because count++ in the for parameter does that job for you. You must have been confused with while )

But where will you get the ‘payment’ from? Something is missing because the program accepts only 1 purchase but is asked to display 12 purchases??

Also I didn’t get why «payment = purchasePrice / 12;» is being done.
And I suspect that purchasePrice is supposed to be an array. Also lastName was never assigned, you can’t call it when it’s not assigned.

Topic archived. No new replies allowed.


Recommended Answers

post one of the files that has the errors, especially the top of the *.cpp file where you have all the includes etc. The problem is most likely missing something like this:

#include <iostream>
using std::cout;

or this

#include <iostream>
using  namespace std; // …

Jump to Post

what would happen if you change you include section to look like this

#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <assert.h>

using namespace std;

Jump to Post

you know, this post seems suspicious. It looks like( at lest to me) that you are
trying to get someone else’s code, who wrote it a while back, to compile so you can use
it either for h.w or for some school related stuff? If you don’t get what graphs …

Jump to Post

All 10 Replies

Member Avatar


Ancient Dragon

5,243



Achieved Level 70



Team Colleague



Featured Poster


12 Years Ago

post one of the files that has the errors, especially the top of the *.cpp file where you have all the includes etc. The problem is most likely missing something like this:

#include <iostream>
using std::cout;

or this

#include <iostream>
using  namespace std; // Not recommended

or like this:

#include <iostream>

int main()
{
   std::cout << "Hello Worldn";
}

Edited

12 Years Ago
by Ancient Dragon because:

n/a

Member Avatar

12 Years Ago

/********************************************************************/
/*                                                                  */
/*  parse (...) :                                                   */
/*       1. Reads the graph problem in extended DIMACS format.      */
/*       2. Prepares internal data representation                   */
/*                                                                  */
/*  Requires Routines:                                              */
/*       1. readProblemLine                                         */
/*       2. readNodeDescription                                     */
/*       3. readArcDescription                                      */
/*                                                                  */
/********************************************************************/
       
// Files to be included:
#include <iostream.h>
using std::cout;
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

//#ifdef NO_ERROR_HANDLING
//#define throw(string)  {cerr << string << "n"; exit(1);}
//#define try
//#endif

inline void swap(arc *e1, arc *e2)
{
  arc temp = *e1;
  *e1 = *e2;
  *e2 = temp;
#ifdef REVERSE_POINTER
  if (e1->reverseArc() != e1)
    {
      e1->reverseArc()->setReverse(e1);
      e2->reverseArc()->setReverse(e2);
    }
  else 
    {
      e1->setReverse(e2);
      e2->setReverse(e1);
    }
#endif
}

void parse()
{
  long   *arc_tail=NULL;          // Internal Array: tails of the arcs
  long   *arc_first=NULL;         /* Internal Array for holding:
                                     - node degree
                                     - position of the first outgoing arc */
  long   tail;                    // Tail of current arc

  long   arc_num;
  long   arc_new_num;
//  DistType   max_cost = 0;

  arc    *arc_current=NULL;       // Pointer to the arc structure
  arc    *arc_new;
  node   *v; 

  long    no_lines=0;             // # of current input line
  long    no_plines=0;            // # of problem-lines
  long    no_nlines=0;            // # of node(source)-lines
  long    no_alines=0;            // # of arc-lines

  char    input_line[MAXLINE];    // For reading input line

/* The main loop:
        -  reads the line of the input,
        -  analises its type,
        -  checks correctness of parameters,
        -  puts data to the arrays,
        -  does service functions
*/
  try{
    while ( gets ( input_line ) != NULL ) {
      no_lines ++;

      switch (input_line[0]) 
	{
	case 'c':                       // Skip lines with comments
	case 'n':                      // Skip empty lines   
	case '':                      // Skip empty lines at the end of file
	case 't':                       // Name of the problem
	  break;
	    
	case 'p':                       // Problem description     
	  if ( no_plines > 0 ) throw("more than one problem line");                         //CHANGE MADE BY AMULYA YADAV.....JUST TO CHECK 
	  no_plines = 1;
   
	  readProblemLine(G,input_line);

	  arc_tail = new long[G.numArcs()]; 
	  arc_first= new long[G.numNodes()+1];
	  for (long i=0; i<G.numNodes()+1; i++) arc_first[i]=0;

	  if ( arc_first == NULL || arc_tail == NULL )
	    throw("can't obtain enough memory to solve this problem");
		     
	  arc_current = G.firstArc();	    // Setting pointer to the current arc
	  break;
	
	case 'n':		               // Node description
	  if ( no_plines == 0 ) throw("problem description must come first");
	  if ( no_nlines > MAX_NODE_LINES) throw("too many nodes in the input");

	  no_nlines++;   
	  readNodeDescription(G,input_line);
	  break;

	
	case 'a':                    // Arc Description
	  if ( no_nlines < MIN_NODE_LINES )  throw("too few nodes lines"); 	    
	  if ( no_alines >= G.numArcs() )  throw("too many arcs input");
		
	  tail = readArcDescription(G,input_line,arc_current);
	  arc_first[tail + 1] ++; /* no of arcs outgoing from tail
                                           is stored in arc_first[tail+1] */

	  // Storing Information About The Arc
	  arc_tail[no_alines] = tail;

#ifdef REVERSE_ARCS  //Add reverse arc as well
	  tail = G.index(arc_current->head());
	  arc_current++;
	  no_alines++;
	  arc_first[tail + 1] ++;
	  arc_tail[no_alines] = tail;
#endif
	  no_alines ++;
	  arc_current ++;
	  break;

	default:
	  throw("unknown line type in the input");
	  break;
	  
	} // End of switch
    }     // End of input loop

/* ----- all is red  or  error while reading ----- */ 

    if ( feof (stdin) == 0 ) throw("reading error");

    if ( no_lines == 0 ) throw("input file is empty");

//if ( no_alines < G.numArcs() ) // Not enough arcs
//  parserError(EN19,no_lines);

#ifdef ARTIFICIAL_SOURCE
    //    G.setSource(SOURCE);

    forallNodes(v,G)  {
      if (!connectedToSource(v)) continue;

      createSourceArc(arc_current,v);  // Create reverse arc at same time
      arc_current++;

      tail =  G.getSource()->index();
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#ifdef REVERSE_ARCS      
      arc_current++;
      tail =  G.index(v);
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#endif // REVERSE_ARCS

    }
#endif // ARTIFICIAL_SOURCE

#ifdef ARTIFICIAL_SINK  
    //    G.setSink(SINK);

    forallNodes(v,G)  {
      if (!connectedToSink(v)) continue;

      createSinkArc(arc_current,v);  // Create reverse arc at same time
      arc_current++;

      tail =  G.index(v);
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#ifdef REVERSE_ARCS      
      arc_current++;
      tail =  G.getSink()->index();
      arc_first[tail + 1] ++;
      arc_tail[no_alines] = tail;
      no_alines++;
#endif // REVERSE_ARCS

    }
#endif // ARTIFICIAL_SINK

    forallNodes(v,G) {
      long indx;
      indx = G.index(v);
      if (v !=  G.firstNode())   arc_first[indx] += arc_first[indx-1];
      v->initAdjList( G.arc_i(arc_first[indx]) );
    }
    // init. sentinel
    G.node_i(G.numNodes())->initAdjList(G.arc_i(G.numArcs()));

    /*
    // setup first arcs, including sentinel node
    long indx, sum;
    sum = 0;
    for (indx = 0; indx <= G.numNodes(); indx++)
      {
	sum+=arc_first[indx];
	v = G.node_i(indx);
	v->initAdjList(G.arc_i(sum));
      }
      */
/********** ordering arcs - linear time algorithm ***********/

/* before below loop arc_first[i+1] is the number of arcs outgoing from i;
   after this loop arc_first[i] is the position of the first 
   outgoing from node i arcs after they would be ordered;
   this value is transformed to pointer and written to node.first[i]
   */


    forallNodes(v,G) {
      long indx;
      indx = G.index(v);
      // AVG      last =  G.index(v->lastOutArc());
                             /* arcs outgoing from i must be cited    
                              from position arc_first[i] to the position
                              equal to initial value of arc_first[i+1]-1  */
      arc *e;

      e = G.arc_i(arc_first[indx]);
      forallRemainingOutArcs(e,v) { 
	arc_num = G.index(e);
	tail = arc_tail[arc_num];
          /* the arc no  arc_num  is not in place because arc cited here
             must go out from indx;
             we'll put it to its place and continue this process
             until an arc in this position would go out from indx */
	while ( tail != indx ) {
	  arc_new_num  = arc_first[tail];
	  arc_new      = G.arc_i(arc_new_num);
	  swap(arc_new,e);
	  arc_tail[arc_num] = arc_tail[arc_new_num];

	  // We Increase arc_first[tail] but Label Previous Position

	  arc_tail[arc_new_num] = tail;
	  arc_first[tail] ++ ;
	  
	  tail = arc_tail[arc_num];
	}
      }
      /* all arcs outgoing from  v  are in place */
    }       

// -----------------------  Arcs Are Ordered  ------------------------- */

// Assigning Output Values

#ifdef SHORTEST_PATH
if ( G.getSource()->adjListIsEmpty() ) throw("no arc out of source");
#endif
   }
#ifndef NO_ERROR_HANDLING
catch(char *str) {
  cerr << input_line;
  cerr << "nLine " << no_lines << " of input - " << str << "n";
  abort();
}
#endif

// Free Internal Memory 
  delete arc_first ; 
  delete arc_tail ;

/* ---------------------------------- */

}

/* --------------------   end of parser  -------------------*/

This is the code that is problematic.Actually ,the code which I have has many files and this is one of them.It has a make file and that is what I try to run by using make install.The errors that show up are:
In file included from lds_run.cc:20:
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:99: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:105: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:106: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:114: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:115: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:136: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:144: error: ‘cout’ was not declared in this scope
/media/HCL_DISK3/bim-1.0/common/base_parser.cc:146: error: ‘cout’ was not declared in this scope


These are just a part of the errors that I’m getting.If you still feel you’re not sure what the problem is.you can go this link http://avglab.com/andrew/soft.html and download the the zip file named BIM…that’s the code I’m trying to run.

Any help will be appreciated.
Thanks,anyway.

Member Avatar

12 Years Ago

I tried changing the iostream.h to iostream also.I’ve tried out all variations that you told me about.But none of them has worked.

Thanks

Member Avatar

12 Years Ago

what would happen if you change you include section to look like this

#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <assert.h>

using namespace std;

Member Avatar

12 Years Ago

Enormous number of errors pop up in wchar2.h and wchar.h which are standard C++ library files and this should definitely not happen.A sample of the errors is as follows:

/usr/include/bits/wchar2.h: In function ‘wchar_t* __wmemcpy_alias(wchar_t*, const wchar_t*, size_t)’:
/usr/include/bits/wchar2.h:28: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:28: error: expected primary-expression before ‘<<’ token
/usr/include/bits/wchar2.h: In function ‘wchar_t* __wmemcpy_chk_warn(wchar_t*, const wchar_t*, size_t, size_t)’:
/usr/include/bits/wchar2.h:32: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:32: error: expected primary-expression before ‘<<’ token
/usr/include/bits/wchar2.h: At global scope:
/usr/include/bits/wchar2.h:36: error: expected ‘;’ before ‘__attribute__’
/usr/include/bits/wchar2.h:36: error: declaration does not declare anything
/usr/include/bits/wchar2.h: In function ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’:
/usr/include/bits/wchar2.h:40: error: redefinition of ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’
/usr/include/wchar.h:327: error: ‘wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)’ previously defined here
/usr/include/bits/wchar2.h:40: error: ‘cout’ was not declared in this scope
/usr/include/bits/wchar2.h:40: error: expected primary-expression before ‘<<’ token

Member Avatar

12 Years Ago

Nathan and Ancient Dragon,any help shall be appreciated………..ive already given u the link in case u want a complete understanding of the problem……
Thanks

Member Avatar

12 Years Ago

you know, this post seems suspicious. It looks like( at lest to me) that you are
trying to get someone else’s code, who wrote it a while back, to compile so you can use
it either for h.w or for some school related stuff? If you don’t get what graphs are
then go study more theory and ask specific questions, otherwise good luck cheating.

———————
PS: forgive if I was wrong.

Member Avatar

12 Years Ago

Dont be bitter if you dont have an answer to the questions asked.And I dont think you are important enough to tell you what am I doing with this code?……….and you know what,I’d even suggest a course in etiquettes for u………….

Member Avatar


Ancient Dragon

5,243



Achieved Level 70



Team Colleague



Featured Poster


12 Years Ago

what compiler are you using anyway? I tried to compile it with vc++ 2010 express and had no problems using

#include <iostream>
using std::cout;
// etc. etc

The code you posted 6 hours ago contains a lot of other problems than just the one you have been complaining about, most likely because you have failed to include other critical header files. You will never get a clean compile without those header files.

Member Avatar

12 Years Ago

Hi Ancient Dragon,
I am using GNU g++ compiler.
and yup,there are a lot of dependencies in between a lot of files so I dont compile them one by one. The scientist who had written this code had written a makefile and i use that to compile and generate the binaries.

I dont think i can post all the files here .there are more than 100 files in the source code. But if you want to get a good look, I have put in the link where you’ll find the code.

Thanks for replying.


Reply to this topic

Be a part of the DaniWeb community

We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sys/socket.h>
#include <sys/unistd.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <iostream>
#include <thread>

using namespace std;

#define BUFFSIZE 2048
#define DEFAULT_PORT 4001    //
#define MAXLINK 2048

void connecter()
{
    printf("Listening...n");
    while (true)
    {
        signal(SIGINT, stopServerRunning);    // 
        // 
        connfd = accept(sockfd, NULL, NULL);
        if (-1 == connfd)
        {
            printf("Accept error(%d): %sn", errno, strerror(errno));
            return -1;
        }
    }
}

void listener()
{
    while(true)
    {
        bzero(buff, BUFFSIZE);
        //
        recv(connfd, buff, BUFFSIZE - 1, 0);
        // 
        printf("клиент: %sn", buff);
        //
        send(connfd, buff, strlen(buff), 0);
    }
}

void sender()
{
    while(true)
    {
        printf("Please input: ");
        scanf("%s", buff);
        send(connfd, buff, strlen(buff), 0);
        bzero(buff, sizeof(buff));
        recv(connfd, buff, BUFFSIZE - 1, 0);
        printf("recv: %sn", buff);
    }
}

int sockfd, connfd; 
void stopServerRunning(int p)
{
    close(sockfd);
    printf("Close Servern");
    exit(0);
}
int main()
{
    struct sockaddr_in servaddr;
    char buff[BUFFSIZE];
    //
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (-1 == sockfd)
    {
        printf("Create socket error(%d): %sn", errno, strerror(errno));
        return -1;
    }
    // 
    // 
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(DEFAULT_PORT);
    if (-1 == bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)))
    {
        printf("Bind error(%d): %sn", errno, strerror(errno));
        return -1;
    }
    // 
    //
    if (-1 == listen(sockfd, MAXLINK))
    {
        printf("Listen error(%d): %sn", errno, strerror(errno));
        return -1;
    }
    
    while(true)
    {
        thread my_thread(connecter);
        if(connfd == true)
            break;
    }

    thread my_thread(connecter);
    thread my_thread(listener);
    thread my_thread(sender);

    return 0;
}

}

это исходный код программы, хотел написать что-то вроде чата на сокетах. Я попытался скомпилировать код, но он мне выдал несколько ошибок «was not declared in this scope». Вот вывод компилятора:

server.cpp: In function ‘void connecter()’:
server.cpp:24:24: error: ‘stopServerRunning’ was not declared in this scope
   24 |         signal(SIGINT, stopServerRunning);    // Это предложение используется для выключения сервера при вводе Ctrl + C
      | 

server.cpp:26:9: error: ‘connfd’ was not declared in this scope
   26 |         connfd = accept(sockfd, NULL, NULL);
      |         ^~~~~~

server.cpp:26:25: error: ‘sockfd’ was not declared in this scope; did you mean ‘socket’?
   26 |         connfd = accept(sockfd, NULL, NULL);
      |                         ^~~~~~
      |                         socket

server.cpp: In function ‘void listener()’:
server.cpp:39:15: error: ‘buff’ was not declared in this scope
   39 |         bzero(buff, BUFFSIZE);
      |               ^~~~

server.cpp:41:14: error: ‘connfd’ was not declared in this scope
   41 |         recv(connfd, buff, BUFFSIZE - 1, 0);
      |              ^~~~~~

server.cpp: In function ‘void sender()’:
server.cpp:54:21: error: ‘buff’ was not declared in this scope
   54 |         scanf("%s", buff);
      |                     ^~~~

server.cpp:55:14: error: ‘connfd’ was not declared in this scope
   55 |         send(connfd, buff, strlen(buff), 0);
      |              ^~~~~~

я думаю, что все эти ошибки идут из одной проблемы, но не могу понять откуда

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error counter logging not supported
  • Error countable or uncountable
  • Error count was not declared in this scope
  • Error count reached перевод
  • Error count parameter must be an array or an object that implements countable

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии