Problem with C++ Language
I am going through a hectic error in c++ language. I am having some critical errors and problems writing a simple program. The only errors I am getting is "undeclared identifier", but the variable is declared and initialized through user input before it is using it
Please help me with this problem
Re: Problem with C++ Language
Example
doy.cpp: In function `int main()':
doy.cpp:25: `DayOfYear' undeclared (first use this function)
doy.cpp:25: (Each undeclared identifier is reported only once for each function
it appears in.)
doy.cpp:25: parse error before `;' token
Meaning
You used "DayOfYear" in your code, but the compiler has not seen a definition for "DayOfYear". It doesn't know what "DayOfYear" is.
Usual Causes
You forgot to include the header file that defines the class/struct/function/etc
You misspelled the name of the identifier
Re: Problem with C++ Language
You cannot nest functions and subroutines in C. Thus, you cannot put the code for Startstr() within main(). You need to do this:
Code:
char *Startstr(char * s, char * sub); // Function prototype
int main() {
.. code for main ..
}
char *Startstr(char * s, char * sub) {
.. code for Startstr
}
Re: Problem with C++ Language
You need to declare s and sub within main(). This is the cause of your error.
Code:
int main() {
char s[50], sub[50];
.. rest of code
}
Re: Problem with C++ Language
You're using the strstr() function. You need to #include <cstring> instead of <string>. Also, you need to declare that you're using the standard namespace:
Code:
#include <iostream>
#include <cstring>
using namespace std;
If you don't have that using statement, you will need to qualify all your objects/functions like this:
std::cout << "...";
std::cin >> "....";