Here is the code:
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std:cin >> v1 >> v2;
std::cout << "The sum of " << v1 << "and " v2 << "is " << v1+v2 << std:endl;
return 0;
}
Here is the error:
g++ x.cpp
#x.cpp: In function ‘int main()’:
#x.cpp:23:9: error: ‘cin’ was not declared in this scope
#x.cpp:23:9: note: suggested alternative:
#In file included from x.cpp:19:0:
#/usr/include/c++/4.7/iostream:61:18: note: ‘std::cin’
#x.cpp:24:48: error: expected ‘;’ before ‘v2’
I have corrected the code, there are several mistakes (this is my first c++ experience):
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << std::endl;
return 0;
}
asked May 11, 2013 at 12:16
1
Here:
std:cin >> v1 >> v2;
// ^
You are missing a colon. It should be:
std::cin >> v1 >> v2;
// ^^
Without the second colon, instead of using the scope resolution operator, you are declaring a label called std
, followed by an unqualified name cin
(which is why the compiler complains about cin
not being declared in this scope).
answered May 11, 2013 at 12:17
Andy ProwlAndy Prowl
123k23 gold badges381 silver badges449 bronze badges
0
You need to add
using namespace std;
as cin
and string
are defined under standard name space std
, which is not the same scope with the main()
body.
The keyword using
technically means, use this whenever you can. This refers, in this case, to the std namespace. So whenever the computer comes across string, cout, cin, endl or anything of that matter, it will read it as std::string
, std::cout
, std::cin
or std::endl
.
When you don’t use the std
namespace, the computer will try to call string
or cin
as if it weren’t defined in a namespace (as most functions in your codes). Since it doesn’t exist there, the computer tries to call something that doesn’t exist! Hence, an error occurs.
You can refer to here for more info and examples.
Note: by doing this, you should also know its disadvantages. Check out Why is “using namespace std;” considered bad practice? for more info.
Better way is that you can put std::
front like std::cin
, std::string
etc to explicitly give their namespaces.
- Forum
- Beginners
- Trying to compile — errors
Trying to compile — errors
Good Day all….
What I have is a soccer game source code (it is a text based game) — I want to make some changes to the code and change some of the features…. Now here are the problems
It is .cpp code and I am trying to compile it as it is (no modifications) I am doing this to see if there are any errors in the existing code before trying to modify…
I am getting 3 errors and 158 warnings — Most of the errors are :
warning: deprecated conversion from string constant to ‘char*’ (with the line of error noted)
the errors are:
In function ‘void get_ref_data()’error: name lookup of ‘i’ changed for ISO ‘for’ scoping note: (if you use ‘-fpermissive’ G++ will accept your code)
In function ‘void run_extratime()’error: ‘cin’ was not declared in this scope
In function ‘int Get_Attendance(int)’error: ‘cin’ was not declared in this scope
Now I am a complete newbie — I am trying to teach myself as I go along but could maybe use some help pointing me in a solution direction… I am not asking anybody to do the work for me but maybe just see if someone can help me find out how to solve the issue (in plain english) — I have looked the errors and such up but I cannot understand what is being said (above my head)…..
I have posted the code on Codepad here:
http://codepad.org/wXIZ1837 (I have not included the header files as they seem to not be the problem yet — but I can if needed)
I can post the error log as well if needed…
Again any help or guidance would be greatly appreciated
Thank You in advance
Well, I hope, I’d be able to explain…^^
The first four errors were that there was a comment beginning (/*) already inside of a comment. The adequate code lines are these ones:
(lines 21 to 26)
|
|
If I’m right, you have to end the comment at each line if you want to ‘re-start’ it every line. So your code should look like this:
|
|
See the comment endings (*/) at the end of each line? If they miss, the compilet complains about a comment within a comment. =)
So this is done. But there are also 2 more errors and one warning.
The ‘first’ error is about your #include "game.h"
. I don’t know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++ you have to hit ALT+P or go by the menu to «Project -> Project Options». Then to the tab «Directories», in there to «Include Direcories» and there youenter the path of the directory your header is in.
The warning is that you ignore the #pragma wrning
. If the compiler says that, he’s almost everytime right. So only delete this line from your source code and then, the copiler should not complain abut that.
The ‘second’ error is abut the fact that you have an array named team[2]
and it’s of the data value struct teams
. If you don’t code, what this teams
thing is, you will not achieve any progress. Also, if you defined teams
in game.h
, you don’t have to write struct teams
. A single teams
is ok =)
If you have any questions, ask them.
@others: If you have any suggestions for improvement, let me know this =)
Last edited on
To your other errors:
In function 'void get_ref_data()'error: name lookup of 'i' changed for ISO 'for' scoping note: (if you use '-fpermissive' G++ will accept your code) In function 'void run_extratime()'error: 'cin' was not declared in this scope In function 'int Get_Attendance(int)'error: 'cin' was not declared in this scope
To the second and third error named in your post above, it’s mentioned that the compiler doesn’t know cin
. The compiler needs a std::cin
. I’m not really sure, but I guess this std::
means that the compiler should look up the following argument in stdlib. As already mentioned, I’m not really sure about this, but it’s right. To clear these errors, you have to use either using namespace std;
at the beginning of your cpp-file or you have to use std::cin
everytime you use cin
. I prefer using the first one in every source file, but if you don’t want to, you don’t want to =).
If I interpret the first error right, it means that you are changing i
where you are not allowed to. I myself would try to find some other soultion having the same result as i--;
but at the moment I don’t really know what to do… =(
In function ‘void get_ref_data()’error: name lookup of ‘i’ changed for ISO ‘for’ scoping note: (if you use ‘-fpermissive’ G++ will accept your code)
This would mean that the code has something like:
|
|
you could change the code or use the compiler switch ‘-fpermissive‘ mentioned.
Grey Wolf is right. It’s in line 1047: int temp = random(i-1);
I’d give you a better version of your get_ref_data:
|
|
I altered the random(i-1)
into random(t-1)
and implemented t
as an int
before the loop and inside I defined t
as i
. At all, it has the same effect as our solution.
So this is done. But there are also 2 more errors and one warning.
The ‘first’ error is about your #include «game.h» . I don’t know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++
Thank You — as far as Game.h — I have that saved (and will post to copy pad)
http://codepad.org/BM43SzF3 <— there it is (and it is in the same directory — the reason it said it could not be found is because YOU did not have it )
@FlashDrive: That’s redundant. Why make a spare variable ‘t’ that just copies ‘i’ 150 times, if you can just move ‘i’ a scope up?
|
|
oh, I understand. The errors are from codepad, aren’t they?
The ‘first’ error is about your #include «game.h» . I don’t know if you compiled the source code as itself or within a project. Anywy this error means that the compiler could not find a file named like this. If you have the header file in anoher directory than the working directory, you have to say this to the compiler. E.g. in DEV-C++ you have to hit ALT+P or go by the menu to «Project -> Project Options». Then to the tab «Directories», in there to «Include Direcories» and there youenter the path of the directory your header is in.
The game.h file is in the same folder — it was an error for you as you did not have it… I have posted it to Codepad
http://codepad.org/BM43SzF3
I also noticed it needed playerroster.h
http://codepad.org/tYGP78cq
Topic archived. No new replies allowed.
kosdin 13 / 12 / 3 Регистрация: 31.10.2019 Сообщений: 70 |
||||
1 |
||||
02.11.2020, 14:41. Показов 3208. Ответов 2 Метки нет (Все метки)
Изучаю C++ и столкнулся с такой вот проблемой.
Выдаёт вот такие ошибки: ‘cin’ was not declared in this scope; ‘cout’ was not declared in this scope
__________________
0 |
Zirak 76 / 68 / 10 Регистрация: 11.07.2016 Сообщений: 320 |
||||
02.11.2020, 14:45 |
2 |
|||
А using namespace лучше не использовать.
0 |
kosdin 13 / 12 / 3 Регистрация: 31.10.2019 Сообщений: 70 |
||||
02.11.2020, 14:47 [ТС] |
3 |
|||
Уже понял в чём была ошибка, забыл прописать
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
02.11.2020, 14:47 |
Помогаю со студенческими работами здесь Was not declared in this scope int y; main.cpp: In function ‘int main()’: ‘mean’ was not declared in this scope ‘mean’ was not declared in this scope ‘mean’ was not declared in this scope Was not declared in this scope
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 3 |
Вот код:
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std:cin >> v1 >> v2;
std::cout << "The sum of " << v1 << "and " v2 << "is " << v1+v2 << std:endl;
return 0;
}
Здесь ошибка:
g++ x.cpp
#x.cpp: In function ‘int main()’:
#x.cpp:23:9: error: ‘cin’ was not declared in this scope
#x.cpp:23:9: note: suggested alternative:
#In file included from x.cpp:19:0:
#/usr/include/c++/4.7/iostream:61:18: note: ‘std::cin’
#x.cpp:24:48: error: expected ‘;’ before ‘v2’
Я исправил код, есть несколько ошибок (это мой первый опыт c++):
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << std::endl;
return 0;
}
1 ответы
Вот:
std:cin >> v1 >> v2;
// ^
Вам не хватает двоеточия. Так должно быть:
std::cin >> v1 >> v2;
// ^^
Без второго двоеточия вместо использования оператора разрешения области действия вы объявляете этикетка под названием std
, за которым следует неполное имя cin
(поэтому компилятор жалуется на cin
не объявляется в этой области).
ответ дан 11 мая ’13, 13:05
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
c++
g++
or задайте свой вопрос.
Я работаю над заданием, в котором мне нужно разбить программу на модули .cpp и .h файлов, и я получаю странную ошибку. В одном из моих файлов .cpp у меня есть код
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>bool getYesNoResponse()
{
string response;
getline (cin, response);
while (response.size() == 0 ||
(response[0] != 'y' && response[0] != 'Y'
&& response[0] != 'n' && response[0] != 'N'))
{
if (response.size() > 0)
cout << "Please respond 'yes' or 'no'. " << flush;
getline (cin, response);
}
return response[0] == 'y' || response[0] == 'Y';
}
Я получаю ошибку error: 'string' was not declared in this scope
, Я не должен редактировать фактический код, данный мне (мы должны только написать include и определить функции в файлах .h), но я хотел посмотреть, была ли проблема со строкой единовременной, поэтому Я заменил string
с std::string
в «string response;
«линия, и проблема прекратилась; кроме того, я получил error: 'cin' was not declared in this scope
со следующей строки. У меня есть мой #include
за <string>
, <iostream>
, а также <fstream>
, так что я довольно смущен тем, почему это не работает. Буду признателен за любой совет, как это исправить без изменения моего исходного кода!
-1
Решение
Вам нужно добавить
using namespace std;
как cin
а также string
определяются под стандартным пространством имен std
, что не совпадает с областью main()
тело.
Ключевое слово using
технически означает, используйте это, когда можете. В данном случае это относится к пространству имен std. Поэтому, когда компьютер сталкивается со строкой, cout, cin, endl или чем-то в этом роде, он будет читать это как std::string
, std::cout
, std::cin
или же std::endl
,
Когда вы не используете std
пространство имен, компьютер будет пытаться позвонить string
или же cin
как будто он не был определен в пространстве имен (как большинство функций в ваших кодах). Поскольку его там нет, компьютер пытается вызвать то, чего не существует! Следовательно, возникает ошибка.
Вы можете обратиться к Вот для получения дополнительной информации и примеров.
Замечания: Делая это, вы также должны знать его недостатки. Проверять, выписываться Почему «использование пространства имен std;» считается плохой практикой? для получения дополнительной информации.
Лучше всего, что вы можете положить std::
фронт как std::cin
, std::string
и т.д., чтобы явно дать их пространства имен.
3
Другие решения
Все эти имена, которые были указаны в сообщениях об ошибках, объявляются в стандартном пространстве имен std. Так что либо вы должны префиксировать такие имена с помощью std ::, то есть использовать квалифицированные имена, как, например,
std::string response;
или вы должны сказать компилятору, что эти неквалифицированные имена будут соответствовать именам из стандартного пространства имен, как, например,
using std::string;
или вы должны поместить все стандартные имена в глобальное пространство имен, как, например,
using namespace std;
0
- Remove From My Forums
-
Question
-
Anyone can debug my error.. I not a code c++ programmer.. tnx<br/><br/><br/>#include<stdio.h> #include<conio.h> #include <string.h> #include<stdlib.h> //conversion #include<ctype.h> #include <io.h> #include<time.h> #define password "skm" using namespace std; //user -define data-type typedef struct { int StuID; int age; char name[30]; char add[30]; char gender[10]; char status[10]; char cno[10]; char date[12]; } stu_rec; typedef struct link{ stu_rec data; struct link*next; }node; typedef struct{ node*Node; }list; //prototypes int menu(); void AddEntry(list*,stu_rec); void DeletEntry(list*, int); void DisplayEntry(node*); void SearchID(list*,int); int isEmpty(node*); stu_rec getRecord(list *); void init(list*); void process(int,list*); void read_file(list*); void write_file(list*); void ModifyEntry (list *mylist, int); void displayRec(node*current); int getID(); void pass(); char cur_date[9]; char cur_time[9]; void main() { cout<<endl; cout<<("nnttt SCHOOL OF COMPUTING & TECHNOLOGY.")<<endl; cout<<("nttt *********************************");<<endl; cout<<("nttt *********************************");<<endl; int valid,retry=1; char pass[10]; _strdate(cur_date); _strtime(cur_time); do { cout<<("Enter The Password: "); gets(pass); if(strcmp(pass,password)!=0) { clrscr(); gotoxy(30,16); cout<<("Incorrect Password!"); valid=0; retry+=1; } else valid=1; }while(!valid&&retry<=3); if(retry>3) { gotoxy(28,16); cout<<("Maximum 3 try only! Bye!"); getch(); exit(0); } else { cout<<("Access approved!"); getch(); } } void init(list*mylist){ mylist->Node=NULL; } void process(int choice,list *mylist){ clrscr(); stu_rec num; int ID; switch(choice) { case 1:num=getRecord(mylist); AddEntry(mylist,num); cout<<("n Record Inserted!"); break; case 2: ID = getID(); DeletEntry(mylist,ID); break; case 3:DisplayEntry(mylist->Node); break; case 4: ID = getID(); ModifyEntry(mylist, ID); break; case 5: ID=getID(); SearchID(mylist,ID); break; case 6: clrscr(); cout<<("nnttt*******T H A N K Y O U !!******"); cout<<("nttt******Done by : KAMRAN MEHDI****"); cout<<("nttt*******PROGRAM TERMINATED******"); break; default:cout<<("INVALID CHOICE!!! PLEASE ENTER AGAIN!"); } getch(); } int menu(){ clrscr(); int temp; gotoxy(13,2); cout<<("DATE: %sn",cur_date); gotoxy(53,2); cout<<("TIME: %sn",cur_time); cout<<("ntt**********************************************"); cout<<("ntt* STUDENT REGISTRATION PROGRAM *"); cout<<("ntt**********************************************"); cout<<("n"); cout<<("nttt[1]Add New Student Record "); cout<<("nttt[2]Delete Student Record "); cout<<("nttt[3]Display Student Record "); cout<<("nttt[4]Modify Student Record "); cout<<("nttt[5]Search Student Record "); cout<<("nttt[6]Exit The Program "); cout<<("nntttPlease Enter Your Choice: "); fflush(stdin); cin>>("%d", &temp); return temp; } boolean IsDuplicate(int temp, list *mylist){ node* curr = mylist->Node; while(curr!= NULL){ if (curr->data.StuID == temp){ cout<<("nt<<StudentID Number already in use !>>"); cout<<("n"); return true; } curr= curr->next; } return false; } int getCode(char *str, list *mylist){ char temp[20]; boolean OK; do{ OK = true; cout>>("%s",str); fflush(stdin); gets(temp); if (strlen(temp)!=4){ cin>>("tt<< Student ID should not be Empty or It should ntt only 4 digits >>n"); OK= false; } for(int count=0; temp[count]!=''; count++) if (!isdigit(temp[count])){ cout>>("tt<< Must be digits! >>n"); OK = false; break; } }while(!OK || IsDuplicate(atoi(temp), mylist)); return atoi(temp); } char *getString(char * str){ char *temp = (char *)malloc(sizeof(80)); cout<<("%s", str); fflush(stdin); gets(temp); return temp; } char *getString(char * str, int size, int status){ char *temp = (char *)malloc(sizeof(80)); boolean OK; do{ OK = true; cout<<("%s", str); fflush(stdin); gets(temp); if (strlen(temp)>size){ cout<<("tt<< Contact No should not be Empty or ntt It should not exceed %d characters! >>n", size); OK = false; } if (status == 1 && strlen(temp)< 4){ cout<<("tt<< Name should not be Empty or ntt It should not less than 4 characters.>>n"); OK = false; for(int count=0; temp[count]!=''; count++) if (!isalpha(temp[count])){ cout<<("tt<< Student Name Must be characters! >>n"); OK = false; break; } } if (status == 2) if (strlen(temp) < 8){ cout<<("tt<<Contact No should not be Empty or nttIt should not less than 8 characters>>n"); OK = false; }else for(int count=0; temp[count]!=''; count++) if (!isdigit(temp[count])){ cout<<("tt<< Contact No Must be numeric!>>n"); OK = false; break; } if (status == 0 && (temp[0]!='m'&& temp[0]!='f' )){ cout<<("tt<< Gender should not be Empty or ntt It should be only M or F >>n"); OK = false; } }while(!OK); return temp; } char * getDate(){ boolean OK; char * temp = (char *)malloc(12); do{ OK = true; cout<<("t Student D.O.B [DD/MM/YYYY]:"); fflush(stdin); gets(temp); if (strlen(temp)!=10){ cout<<("tt<< Student D.O.B should not be Empty or ntt It should Must be 10 characters >>n"); OK = false; }else if (!isdigit(temp[0]) || !isdigit(temp[1]) || !isdigit(temp[3]) || !isdigit(temp[4]) || !isdigit(temp[6])|| !isdigit(temp[7]) || !isdigit(temp[8]) || !isdigit(temp[9]) || temp[2]!='/' || temp[5]!='/'){ cout<<("tt<< Student D.O.B Format must be dd/mm/yyyy >>n"); OK = false; } else if (temp[0] < '0' || temp[0] >'3'){ cout<<("tt<< Invalid day >>n "); OK = false ; }else if (temp[3] < '0' || temp[3] > '1' || temp[4] < '0' || temp[4] > '2') { cout<<("tt<< Invalid month >> n"); OK = false ; }else if (temp[6] < '1' || temp[6] >'2'){ cout<<("tt<< Invalid year >>n "); OK = false ; } }while(!OK); return temp; } stu_rec getRecord(list *mylist){ stu_rec temp; clrscr(); cout<<("ntt******************************************"); cout<<("ntt*********ADD NEW STUDENT RECORD***********"); cout<<("ntt******************************************"); cout<<("n"); temp.StuID=getCode("t Student ID: ",mylist); strcpy(temp.name,getString("t Student Name:", 30,1)); do{ strcpy(temp.add,getString("t Student address:")); if(strlen(temp.add)<10) cout<<("tt<< Address should not be Empty or nttIt should not less than 10 characters >>n"); }while(strlen(temp.add)<10); strcpy(temp.gender,getString("t Student Gender [F or M]:",1,0)); do{ cout<<("t Student Age:"); cin>>("%d",&temp.age); if((temp.age)<3) cout<<("t <<Student age should not be Empty or nttIt should not more than 2 character>>n"); }while((temp.age)<3); strcpy(temp.cno,getString("t Student Contact No:",10,2)); do{ strcpy(temp.status,getString("t Marital Status:")); if(strlen(temp.status)>10) cout<<("tt<<Marital Status should not be Empty or nttIt should not exceed 10 characters>>n"); }while(strlen(temp.status)>10); strcpy(temp.date,getDate()); cout<<("ntPlease Press any key to continue!!"); getch(); clrscr(); return temp; } int isEmpty(node* thelist){ if(thelist == NULL) return 1; else return 0; } void AddEntry(list*mylist, stu_rec x){ node*newPtr=(node*)malloc(sizeof(node)); node*prev=mylist->Node; newPtr->data=x; newPtr->next=NULL; if (isEmpty(mylist->Node)) mylist->Node=newPtr; else if (mylist->Node->data.StuID > newPtr->data.StuID){ newPtr->next = mylist->Node; mylist->Node = newPtr; }else { while((prev->next!=NULL) &&(prev->next->data.StuID <x.StuID)) prev=prev->next; newPtr->next=prev->next; prev->next=newPtr; } } int getID(){ int x; cout<<("nPlease Enter Student ID: "); cin>>("%d", &x); return x; } void DeletEntry(list*mylist, int x){ node*prev = mylist->Node; node*target; if(!isEmpty(mylist->Node)) if(mylist->Node->data.StuID == x){ displayRec(mylist->Node); cout<<("nDelete this Record [Y] >> "); if (toupper(getche()) == 'Y'){ mylist->Node = mylist->Node->next; free(prev); cout<<("n Record Deleted!"); getch(); } } else{ target = mylist->Node; while((target!=NULL)&&(target->data.StuID !=x)){ prev = target; target=target->next; } if((target!=NULL) && (target->data.StuID==x)){ displayRec(target); cout<<("nDelete this Record [Y] >> "); if (toupper(getche()) == 'Y'){ prev->next= target->next; cin<<("n Record Deleted!"); getch(); free(target); getch(); } } else cout<<("n Record Does Not Exist!"); cout<<("n Please Press Any Key to Cotinue!!"); getch(); } } void DisplayEntry(node*thelist){ node*current=thelist; if(isEmpty(thelist)){ cout<<("nNo values insert by the user yet!!"); getch(); }else clrscr(); cout<<("ntt*************************************************"); cout<<("ntt *********DISPLAY STUDENT RECORD****************"); cout<<("ntt*************************************************"); cout<<("n"); while(current!=NULL){ clrscr(); displayRec(current); current=current->next; } } void displayRec(node*current){ if (current->data.StuID!=0){ cout<<("ntStudent ID :%d",current->data.StuID); cout<<("ntName :%s",current->data.name); cout<<ntAddress :%s",current->data.add); cout<<ntGender :%s",current->data.gender); cout<<("ntStatus :%s",current->data.status); cout<<("ntAge :%d",current->data.age); cout<<("ntContact Number :%s",current->data.cno); cout<<("ntStudent D.O.B :%s ",current->data.date); cout<<("nnt Press any key to continue!!"); getch(); current=current->next; } } node * update(node * curr){ cout<<ange Address [Y] >> "); if (toupper(getche())== 'Y'){ fflush(stdin); cout<<ter new Address >> "); gets(curr->data.add); } cout<<ange contact No >>[Y] "); if (toupper(getche())== 'Y'){ cout<<ter new contact No >> "); gets(curr->data.cno); } return curr; } void ModifyEntry(list *mylist, int ID){ node *curr = mylist->Node; while(curr!=NULL){ if(curr->data.StuID==ID){ clrscr(); cout<<("ntt*************************************************"); cout<<("ntt**********R E C O R D F O U N D!!*************"); cout<<("ntt*************************************************"); cout<<("n"); displayRec(curr); curr = update(curr); return; } curr = curr->next; } cout<<("Record does not exist!"); } void SearchID(list*mylist, int x) { node*curr=mylist->Node; while(curr!=NULL) { if(curr->data.StuID==x) { clrscr(); cout<<("ntt*************************************************"); cout<<("ntt**********R E C O R D F O U N D!!*************"); cout<<("ntt*************************************************"); cout<<("n"); displayRec(curr), getch(); break; } curr=curr->next; } if(curr==NULL){ cout<<("nt Sorry Record Does Not Exist!!"); cout<<("nt Please PRESS any key to continue!!"); getch(); clrscr(); } } void write_file(list*mylist){ clrscr(); FILE *fp; stu_rec temp; node* curr = mylist->Node; if ((fp=fopen("c:data.dat", "wb"))==NULL) cout<<("aError opening File! "); else{ //printf("nRecords Written to file from list!!"); while (curr!=NULL){ temp = curr->data; fwrite((void *) &temp,sizeof(stu_rec),1,fp); curr=curr->next; } fclose(fp); } } void read_file(list*mylist){ clrscr(); FILE *fp; node *curr; node * prev =NULL; stu_rec temp; if ((fp=fopen("c:Data.dat", "rb"))==NULL) cout<<("aError opening File! "); else{ //printf("nRecords Written from binary file to list!"); while (!feof(fp)){ fread((void *)&temp,sizeof(stu_rec),1,fp); AddEntry(mylist, temp); } curr = mylist->Node; while (curr->next!=NULL){ prev = curr; curr=curr->next; } if (prev!=NULL) prev->next = curr->next; // DeletEntry(mylist,temp.StuID); fclose(fp); } } { system("PAUSE"); return EXIT_SUCCESS; }
Answers
-
>Anyone can debug my error..
What error? I don’t see any description of it. I don’t
see any mention of which compiler and version you’re
using. Don’t make us guess these things. Spell it out.The use of clrscr() and gotoxy() indicate that this
program was written for another compiler, probably
Borland/Turbo C++. It can’t be built with Visual C++.
It will have to be modified to replace the unsupported
functions and features.— Wayne
-
Marked as answer by
Sunday, March 20, 2011 6:15 AM
-
Marked as answer by
-
Sorry, but you have a lot of different errors there. I’m afraid you’ll need a programmer to sort through them and make changes appropriate for your particular compiler, platform, and objectives.
Jonathan Wood • Black Belt Coder
-
Marked as answer by
MiCzZz
Sunday, March 20, 2011 6:16 AM
-
Marked as answer by