Returing string from main function in c++ -
is there way return string main function in c++? mentioning sample program below
string main(int argv, char* argc[]) { . . return "sucess"; }
the standard says:
3.6.1 main function [basic.start.main]
2/ implementation shall not predefine main function. function shall not overloaded. it shall have return type of type int, otherwise type implementation-defined. implementations shall allow both
- a function of () returning int and
- a function of (int, pointer pointer char) returning int
as type of main. [...]
so no, have return int.
from comments on post, seem want output string on standard output, can do:
#include <iostream> int main() { std::cout << "success" << std::endl; // no need return 0; implicit in c++ }
as kerrek sb said in comments, return 0;
implicit in c++ (standard § 3.6.1 /5):
[...] if control reaches end of
main
without encounteringreturn
statement, effect of executingreturn 0;
Comments
Post a Comment