Hi.
I have a piece of code that can be compiled and linked both with
Cygwin g++ and with VC++. The code is:
//WORKS WITH CYGWIN G++
//BUT NOT WITH CL.EXE (VC++) (compiles, but error when executed)
//################################
#include <iostream>
#include <sstream>
using namespace std;
int main ()
{
int val;
string mystr;
stringstream ss (stringstream::in | stringstream::out);
cout.rdbuf(ss.rdbuf()); //Is this ok to do?
cout << "120 42 377 6 5 2000";
//If the two lines above are replaced with
//this line it works fine with both
//g++ and VC++:
//ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++)
{
ss >> val;
cerr << val*2 << '\n';
}
cerr << "Hello World! " << endl;
return 0;
}
//################################
My problem is that during run time the exe-file that was created with
Cygwin g++ (3.3.1) works fine, but the exe-file that was created with
VC++ 6.0 crashes.
Here is the error message:
The instruction at "0x00402f7f" referenced memory at "0x0000000sd".
The memory could not be "read".
Is there any errors in my code, or do I do something I'm not allowed
to?
Since it works in Cygwin g++, but not in VC++ 6.0 I think this is
really strange, since I believe that my code is 100% ANSI-C++ code. Or
is it?
I compile with:
G++: g++ test.cpp
VC++: cl /GX /TP test.cpp (also compiled with the entire VC++
development GUI)
I'm thankful for any information that might help me with this problem.
/Omid 3 5633
"Omid" <n_********@hotmail.com> wrote in message
news:77**************************@posting.google.c om... Hi.
I have a piece of code that can be compiled and linked both with Cygwin g++ and with VC++. The code is:
//WORKS WITH CYGWIN G++ //BUT NOT WITH CL.EXE (VC++) (compiles, but error when executed) //################################ #include <iostream> #include <sstream> using namespace std;
int main () {
int val; string mystr; stringstream ss (stringstream::in | stringstream::out);
cout.rdbuf(ss.rdbuf()); //Is this ok to do? cout << "120 42 377 6 5 2000";
//If the two lines above are replaced with //this line it works fine with both //g++ and VC++: //ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++) { ss >> val; cerr << val*2 << '\n'; }
cerr << "Hello World! " << endl; return 0; } //################################ My problem is that during run time the exe-file that was created with Cygwin g++ (3.3.1) works fine, but the exe-file that was created with VC++ 6.0 crashes.
Here is the error message: The instruction at "0x00402f7f" referenced memory at "0x0000000sd". The memory could not be "read".
Is there any errors in my code, or do I do something I'm not allowed to? Since it works in Cygwin g++, but not in VC++ 6.0 I think this is really strange, since I believe that my code is 100% ANSI-C++ code. Or is it?
I compile with: G++: g++ test.cpp VC++: cl /GX /TP test.cpp (also compiled with the entire VC++ development GUI)
I'm thankful for any information that might help me with this problem.
/Omid
You must restore the old buffer before you exit.
streambuf* save_buffer = cout.rdbuf(ss.rdbuf()); //Is this ok to do?
cout << "120 42 377 6 5 2000";
cout.rdbuf(save_buffer);
john
"Omid" <n_********@hotmail.com> wrote in message
news:77**************************@posting.google.c om... Hi.
I have a piece of code that can be compiled and linked both with Cygwin g++ and with VC++. The code is:
//WORKS WITH CYGWIN G++ //BUT NOT WITH CL.EXE (VC++) (compiles, but error when executed) //################################ #include <iostream> #include <sstream> using namespace std;
int main () {
int val; string mystr; stringstream ss (stringstream::in | stringstream::out);
cout.rdbuf(ss.rdbuf()); //Is this ok to do? cout << "120 42 377 6 5 2000";
//If the two lines above are replaced with //this line it works fine with both //g++ and VC++: //ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++) { ss >> val; cerr << val*2 << '\n'; }
cerr << "Hello World! " << endl; return 0; } //################################ My problem is that during run time the exe-file that was created with Cygwin g++ (3.3.1) works fine, but the exe-file that was created with VC++ 6.0 crashes.
Here is the error message: The instruction at "0x00402f7f" referenced memory at "0x0000000sd". The memory could not be "read".
Is there any errors in my code, or do I do something I'm not allowed to? Since it works in Cygwin g++, but not in VC++ 6.0 I think this is really strange, since I believe that my code is 100% ANSI-C++ code. Or is it?
I compile with: G++: g++ test.cpp VC++: cl /GX /TP test.cpp (also compiled with the entire VC++ development GUI)
I'm thankful for any information that might help me with this problem.
/Omid
I just tried with VS.NET and it compiles and runs cleanly. You can download
the compiler for free http://msdn.microsoft.com/visualc/vctoolkit2003/.
"John Harrison" <jo*************@hotmail.com> wrote in message news:<2m************@uni-berlin.de>... "Omid" <n_********@hotmail.com> wrote in message news:77**************************@posting.google.c om... Hi.
I have a piece of code that can be compiled and linked both with Cygwin g++ and with VC++. The code is:
//WORKS WITH CYGWIN G++ //BUT NOT WITH CL.EXE (VC++) (compiles, but error when executed) //################################ #include <iostream> #include <sstream> using namespace std;
int main () {
int val; string mystr; stringstream ss (stringstream::in | stringstream::out);
cout.rdbuf(ss.rdbuf()); //Is this ok to do? cout << "120 42 377 6 5 2000";
//If the two lines above are replaced with //this line it works fine with both //g++ and VC++: //ss << "120 42 377 6 5 2000";
for (int n=0; n<6; n++) { ss >> val; cerr << val*2 << '\n'; }
cerr << "Hello World! " << endl; return 0; } //################################ My problem is that during run time the exe-file that was created with Cygwin g++ (3.3.1) works fine, but the exe-file that was created with VC++ 6.0 crashes.
Here is the error message: The instruction at "0x00402f7f" referenced memory at "0x0000000sd". The memory could not be "read".
Is there any errors in my code, or do I do something I'm not allowed to? Since it works in Cygwin g++, but not in VC++ 6.0 I think this is really strange, since I believe that my code is 100% ANSI-C++ code. Or is it?
I compile with: G++: g++ test.cpp VC++: cl /GX /TP test.cpp (also compiled with the entire VC++ development GUI)
I'm thankful for any information that might help me with this problem.
/Omid
You must restore the old buffer before you exit.
streambuf* save_buffer = cout.rdbuf(ss.rdbuf()); //Is this ok to do? cout << "120 42 377 6 5 2000"; cout.rdbuf(save_buffer);
john
Thanks John!
That solved my problem.
/Omid This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Smith |
last post by:
so is there any alternative ( standard only ) to using in_avail()?
I need to poll with given intervals the input stream, and if there is
data to be read I want to read it.
thank you
/B
|
by: wukexin |
last post by:
Hi, hot heart men:
I have a program in file input and output. I need copy the whole source file's content to a string only once, I don't know what? Help me? thank you.
wukexin...
|
by: Siemel Naran |
last post by:
My compiler (Borland C++) fails to compile this code:
ifstream file(filename.c_str());
ostringstream out;
file >> out.rdbuf();
with the error in the 3rd line above that:
realmain.cpp(83):...
|
by: Alex Vinokur |
last post by:
I tried to print
cout << "<" << infile.rdbuf() << ">" << endl;
while infile is empty.
Here is what I have got.
<
I expected to get
<>
|
by: Zaharije Pasalic |
last post by:
What is purpose of rdbuf methode of stream class? Is rdbuf create new
buffer or just return some kind of pointer to existing?
Thanks,
Zaharije Pasalic
| |
by: Joe Greene |
last post by:
Compiling this file produces the "no appropriate default constructor available" error
shown below. Can anyone explain why I'm getting this error and how to fix it???
This source file has been...
|
by: kelvSYC |
last post by:
Suppose I have something like this:
class foo {
std::istream in;
public:
foo(std::istream& in_) : in(in_.rdbuf());
void doStuffWith(std::ostream& out);
void bar();
};
|
by: srikar |
last post by:
hi
In C++ can any one explain me the meaning of this instruction.
here line is the object of the class strstream i.e strstream &line
line.get( *output.rdbuf(), ' ' );...
|
by: whatdoineed2do |
last post by:
hi,
i'm trying avoid uncessary copy of data whilst using the stringstream
so i am using the sgetn() to copy the data into a buf as apposed to
getting the same data via the .str() which will...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |