![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Mar 2006
Posts: 60
Rep Power: 3
![]() |
Problem with Visual C++ Express
I've just started working on a project, in which part of the code is pre-written. This line generates an error message:
using std::time; The compiler complains that time isn't a member of std. I don't know whether it is, but that code is supposed to work. As I mentioned in the title, I'm using Visual C++ 2005 Express edition. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Did you include the appropriate header? A 'using' statement doesn't magically crap these thangies, it just announces their birth.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Mar 2006
Posts: 60
Rep Power: 3
![]() |
First I had time and stdlib, but VC++ didn't like these so I had to change them to time.h and stdlib.h. Does that explain the error?
Edit: Actually I think is does, and that it has to do with the fact that namespace was new in C++ and *.h is from C. And it seems to work simply by excluding that using-declaration. I'm not planning on duplicating any identifier anyway. Last edited by Xyhm; Apr 19th, 2006 at 10:12 PM. |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 4
![]() |
I'm not sure about VC++ but if it follows the C++ standard then you generally would include <ctime> and <cstdlib> header files. By appending a "c" to the C header filename and dropping the .h extension C++ will make available the C functions you're used to. As a note, you might still have to whatever namespace you want to use but I'm hoping someone else can clarify that since I've never done VC++.
|
|
|
|
|
|
#5 | |
|
Programmer
Join Date: Mar 2006
Posts: 60
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
I got another question, on a really basic level. If in VC++, I want to have string objects, and in my program I have:
#include "stdafx.h" #include "Form1.h" #include "string.h" //or <cstring> or <string>, they all give the same errors as below . . . string str1 = "text"; And I get the following errors: .\Till Program.cpp(18) : error C2065: 'string' : undeclared identifier .\Till Program.cpp(18) : error C2146: syntax error : missing ';' before identifier 'str1' .\Till Program.cpp(18) : error C2065: 'str1' : undeclared identifier Could somebody tell me what I missed, because in regular C++, that should work. |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
In regular C++ that would not work either, you need to use the std namespace.
Cstring/string.h is not what you want, those are just functions to C strings (i.e. char arrays). #include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "bla";
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Again, Visual C++ is a compiler. It works with the ordinary C++ language, the ordinary C++ libraries. Write good code, you're pooty much home free. Compilers are, of course, platform dependent. Some manufacturers include proprietary extensions. Best to steer clear of those. Some are more or less compliant with the standards. VC++ 2005 isn't too bad, in my experience.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 | |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|