F
Forecast
I run the following code in UNIX compiled by g++ 3.3.2 successfully.
: // proj2.cc: returns a dynamic vector and prints out at main~~
: //
: #include <iostream>
: #include <vector>
:
: using namespace std;
:
: vector<string>* getTyphoon()
: {
: vector<string>* typhoonList = new vector<string>();
: typhoonList->push_back("A");
: return typhoonList;
: }
:
: int main(int argc, char* argv[]){
: vector<string> typhoonList = *getTyphoon();
: string A = typhoonList.at(0);
: cout << "A: " << A << endl;
:
: return 0;
: }
But as I transfer the code to MS Visual C++, error appears.
What make me frustrated is that after certain modification, I compiled
"successfully" (with some warnings), but the program still hangs during
runtime (the WinXP error reporting dialogue is appeared).
(1) Anyone kindly knows what's the problem? (Following is the code after
modification)
: // proj2.cpp : Defines the entry point for the console application.
: //
: #include "stdafx.h"
: #include <iostream>
: #include <vector>
:
: using namespace std;
:
: vector<string>* getTyphoon(){
: vector<string>* typhoonList = new vector<string>();
: typhoonList->push_back("A");
: return typhoonList;
: }
:
: int main(int argc, char* argv[]){
: vector<string> typhoonList = *getTyphoon();
:
: string A = typhoonList.at(0);
: printf("%s\n", A);
:
: return 0;
: }
(2) I tried to compile the second code in UNIX again... (that's using the
"printf" and removal of #include "stdafx.h"), the following error is out,
what does it mean?
: user@honest user> g++ test.cc -o test
: test.cc: In function `int main(int, char**)':
: test.cc:26: warning: cannot pass objects of non-POD type `struct
std::string'
: through `...'; call will abort at runtime
: user@honest user>
It would be glad if anyone can help me solve the problem...
: // proj2.cc: returns a dynamic vector and prints out at main~~
: //
: #include <iostream>
: #include <vector>
:
: using namespace std;
:
: vector<string>* getTyphoon()
: {
: vector<string>* typhoonList = new vector<string>();
: typhoonList->push_back("A");
: return typhoonList;
: }
:
: int main(int argc, char* argv[]){
: vector<string> typhoonList = *getTyphoon();
: string A = typhoonList.at(0);
: cout << "A: " << A << endl;
:
: return 0;
: }
But as I transfer the code to MS Visual C++, error appears.
What make me frustrated is that after certain modification, I compiled
"successfully" (with some warnings), but the program still hangs during
runtime (the WinXP error reporting dialogue is appeared).
(1) Anyone kindly knows what's the problem? (Following is the code after
modification)
: // proj2.cpp : Defines the entry point for the console application.
: //
: #include "stdafx.h"
: #include <iostream>
: #include <vector>
:
: using namespace std;
:
: vector<string>* getTyphoon(){
: vector<string>* typhoonList = new vector<string>();
: typhoonList->push_back("A");
: return typhoonList;
: }
:
: int main(int argc, char* argv[]){
: vector<string> typhoonList = *getTyphoon();
:
: string A = typhoonList.at(0);
: printf("%s\n", A);
:
: return 0;
: }
(2) I tried to compile the second code in UNIX again... (that's using the
"printf" and removal of #include "stdafx.h"), the following error is out,
what does it mean?
: user@honest user> g++ test.cc -o test
: test.cc: In function `int main(int, char**)':
: test.cc:26: warning: cannot pass objects of non-POD type `struct
std::string'
: through `...'; call will abort at runtime
: user@honest user>
It would be glad if anyone can help me solve the problem...