| | |
(beginner) this simple code just errors
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 8
Reputation:
Solved Threads: 0
Hello all, i'm new to C++. I'm struggling to run this simple program..
I created a file called source.cpp that the code below. I have no other files in the same project..
Spec: Windows vista, Visual c++ 2008 compiler, 32bits
1>time - 1 error(s), 0 warning(s)
I created a file called source.cpp that the code below. I have no other files in the same project..
Spec: Windows vista, Visual c++ 2008 compiler, 32bits
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <time.h> void main() { char sdate[9]; char stime[9]; _strdate( sdate ); _strtime( stime ); cout << "time: " << stime << " date: " << sdate; //cout << "Hi "; return 0; }
1>time - 1 error(s), 0 warning(s)
•
•
Join Date: Sep 2009
Posts: 312
Reputation:
Solved Threads: 34
0
#4 30 Days Ago
Firstly, you should be creating it as a Win32 console project.
Secondly,
P.S. find the errors in the output tab at the bottom of the screen, after you've run your build
Secondly,
#include <iostream> , as iostream.h is non-standard. Start with those and it should give you two warnings and an error. The warnings are about using your two time functions with an _s at the end, which makes them safer from buffer overflows which can be a security issue down the line. You need a using statement to clarify your cout call.P.S. find the errors in the output tab at the bottom of the screen, after you've run your build
Last edited by jonsca; 30 Days Ago at 5:10 am.
•
•
Join Date: Oct 2009
Posts: 8
Reputation:
Solved Threads: 0
0
#5 30 Days Ago
This seems to have fixed it. I also changed to #include <iostream>
Thank you. How would you write it?
C++ Syntax (Toggle Plain Text)
std::cout << "time: " << stime << " date: " << sdate;
Thank you. How would you write it?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <time.h> void main() { char sdate[9]; char stime[9]; _strdate( sdate ); _strtime( stime ); std::cout << "time: " << stime << " date: " << sdate; //cout << "Hi "; //return 0; system("pause >nul"); }
•
•
Join Date: Sep 2009
Posts: 312
Reputation:
Solved Threads: 34
1
#9 27 Days Ago
The main function is supposed to return a status to the invoking program (e.g., the operating system) so when people have declared main() as returning an int and they say
For your second question, yes, but it's slightly more complicated than in C#. You still need a collection of some sort, but your collection must of the Standard Template Library variety (e.g., vector). Check out http://www.cplusplus.com/reference/algorithm/for_each/ to see all the requirements.
return 0; they really mean that the program executed successfully (there are other error codes used in specific circumstances where the execution has been interrupted). It is "doomed" because a C++ program abiding by the standard should have a main returning int. void main() is outdated.For your second question, yes, but it's slightly more complicated than in C#. You still need a collection of some sort, but your collection must of the Standard Template Library variety (e.g., vector). Check out http://www.cplusplus.com/reference/algorithm/for_each/ to see all the requirements.
Last edited by jonsca; 27 Days Ago at 5:04 pm.
![]() |
Similar Threads
- Code Snippet: VB Simple Tasks with simple code (Visual Basic 4 / 5 / 6)
- Need help with simple code (C++)
- Getting error for the simple code Please help me out (VB.NET)
- why is this simple code using 100% CPU? (Java)
- Simple code help (Python)
- Odd Errors When Compiling Winsock Code. (C++)
- errors in game code (C++)
- simple code (C++)
- CAn anyone provide me a very simple code for shopping cart? (PHP)
Other Threads in the C++ Forum
- Previous Thread: plz help me with this
- Next Thread: programming question
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






