עזרה בc++ אולי אתם תדעו

א ה מ

New member
עזרה בc++ אולי אתם תדעו

כתבתי קטע מתוכנית והקומפיילר לא זהה בעיות וכשהרצתי הוא עשה צרות (מפורט למטה): #include <iostream.h> #include <fstream.h> //for the input and output files #include <stdlib.h> //for rand #include <time.h> //for srand(time); #include <iomanip.h> //for setw(); //******************************************************************************************* //********************** GLOBALS ************* //******************************************************************************************* //**************************************************************** //******************* FUNCTIONS - DECLARATIONS ******************* void GetData (char cInputString, ifstream &input);//reads the contents of the file and inserts it //into a string //***************************************************************** //*************************** STARTING **************************** int main() //the main part of the program { ifstream input; //for reading ofstream output; //for writing input.open("input.txt",ios::in);//open for reading output.open("output.txt",ios::eek:ut); //open for writing char cInputString[1421]=" "; //for the input if(!input) //if the "open" didn't work { exit(0); //stop everything!!! }//end of if else { GetData (cInputString[1421],input); } input.close(); //close-reading output.close(); //close-writing return 0; }//end of main //***************************************************************** //*************************** FUNCTIONS *************************** //******************FUNCTION GET DATA**************************** // reads the contents of the file and inserts it into a string * //*************************************************************** void GetData (char cInputString[1421], ifstream &input) { int iPlace=0; //for the place in the string while (!input.eof()) //runs until the end of the input { input.get(cInputString[iPlace]); //inserts chars into the string iPlace=iPlace+1; } }//end of GetData ההערה: -------------------Configuration: third13 - Win32 Debug-------------------- Linking... third13.obj : error LNK2001: unresolved external symbol "void __cdecl GetData(char,class ifstream &)" (?GetData@@YAXDAAVifstream@@@Z) Debug/third13.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. third13.exe - 2 error(s), 0 warning(s) מה לעשות? תודה!!
 

vicz

New member
לא מימשת את המתודה GetData

אם אתה עדיין מתקשה - תודיע
 

א ה מ

New member
תודה תודה! :)

עדיין יש לי בעיה עם השורה הזאת: if( (**(pNames+i)==(*pName)) && (pName!=*(pNames+i))) (pNames הוא מערך של מצביעים לchar ו pName הוא מצביע לchar ניסיתי לבדוק אם הערך שלהם זהה והכתובת שונה..) וטענת הקומפיילר: --------------------Configuration: third13 - Win32 Debug-------------------- Compiling... third13.cpp C:\Documents and Settings\DAVID\Desktop\third13.cpp(290) : error C2100: illegal indirection C:\Documents and Settings\DAVID\Desktop\third13.cpp(290) : error C2446: '!=' : no conversion from 'char *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast C:\Documents and Settings\DAVID\Desktop\third13.cpp(290) : error C2040: '!=' : 'int' differs in levels of indirection from 'char *' Error executing cl.exe. third13.obj - 3 error(s), 0 warning(s) (אני בת..)
 

vinney

Well-known member
נו, הקומפיילר כתב לך

צריך לעשות cast. בCPP אין כזה דבר implicit cast לטיפוסים לא תואמים, צריך להגיד לו בדיוק למה התכוונת.
 

א ה מ

New member
אני לא מבינה בתכנות כלום.

מה זה cast? מה זה implict cast? אני מנסה להגיד לו מה אני רוצה ולא מצליחה, יש לך דרך יותר ברורה לעשות את זה? (כל התרגיל נתקע לי בגלל השורה הזאת..)
 

vinney

Well-known member
cast זה דרך לגרום לקומפיילר

להתייחס למשתנה מטיפוס X כמשתנה מטיפוס Y. במקרה שלך, למשל, זה יהיה בערך ככה:
char *x; char *y[10]; ... בודקים אם האיבר החמישי במערך הוא כמו המשתנה: if ((void*)x == (void*)y[5])...​
בגדול
כמובן שכל השרשור הזה מקומו בפורום שפות תכנות.
 

א ה מ

New member
הסתבכתי..

מה עשית? ואיך אני בעצם צריכה לכתוב את זה? (אסור לי להשתמש בסוגריים מרובעים) שאלתי גם שם ולא ענו לי.. וממש תודה!!!!!!!!!!
 

א ה מ

New member
אתה יכול אולי לכתוב לי

איך אני אמורה לכתוב את הפקודה שלי כמו שאמרת? (כי לא ממש הבנתי) if( (**(pNames+i)==(*pName)) && (pName!=*(pNames+i))) (ואשמח גם להסבר מה זה הvoid באמצע..)
 

א ה מ

New member
נראה לי שהבנתי איך לכתוב

וזה גם עובר את הקומפיילר!! :) אבל בריצה: -------------------Configuration: third13 - Win32 Debug-------------------- Linking... third13.obj : error LNK2001: unresolved external symbol "struct Apartment * __cdecl SearchSame(char *,struct Apartment (* const)[7],char * * const)" (?SearchSame@@YAPAUApartment@@PADQAY06U1@QAPAD@Z) Debug/third13.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. third13.exe - 2 error(s), 0 warning(s) נראה לי שזאת אותה בעיה שהיתה לי למעלה.. אני לא יודעת למה הוא מחליט את זה.
 

yythe1

New member
הקומפיילר שלך בכלל תקין?

תנסי לקמפל כשה-main שלך ריק ואין פונקציות בקוד , רק תשאירי includes בראש הקובץ
 

vinney

Well-known member
אולי פשוט תקחי ספר לCPP?

יש בשאלות נפוצות של פורום שפות תכנות קישור לאחד טוב.
 

א ה מ

New member
אני בשמחה אעשה את זה אחרי

שאגיש את התרגיל הזה ויהיה לי זמן. אני יושבת עליו המון המון המון זמן ואני חייבת כבר להגיש אותו. אם תוכלו לעזור לי, אני ממש ממש אודה לכם!!!
 
למעלה