Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++: aggregate std::ostringstream has incomplete type?2

3,070 views
Skip to first unread message

picasso

unread,
Feb 12, 2009, 7:43:14 AM2/12/09
to
Hello, I am a newbie, writing a program to take input - in the form of a
file mydata.txt. This contains a single line of plain text data which is
hidden behind askerisks. so the data looks like eg ********.

All my program does is take this input and process it by converting the
******** into raw binary data. It then reads each part of the string and
should then output the string in plain characters.

This is what I have done:

#include <iostream>
#include <fstream>
#include <ostream>
#include <strstream>

int main()
{
std::ifstream infile("mydata.txt", std::ios::binary); // converts the
**** into binary.
if(infile)
{
while(not infile.eof())
{
std::ostringstream data;
data << infile.get() << ' ';
std::cout << data.str();
}

else std::cout << "Failed to read file \n";
}

This is a very simple toy program, but i cant seem to make it work. Im
just starting learning C++.

This program wont compile. These are the 1 error and 1 warning I get:

1. aggregate 'std::ostringstream data' has incomplete type and cannot be
defined.

2. this file includes at least one deprecated or antiquated header.

Can anybody help me to get the program to work please?

Triple-DES

unread,
Feb 12, 2009, 8:10:04 AM2/12/09
to

#include <sstream> instead of <strstream> for ostringstream
You're missing a '}' before the 'else'.

That should get you started...

picasso

unread,
Feb 12, 2009, 10:20:35 AM2/12/09
to

Thanks, I changed the header and at least it compiles now:


> #include <iostream>
> #include <fstream>
> #include <ostream>

> #include <sstream>
>
> int main()
> {
> std::ifstream infile("data.txt", std::ios::binary);


> if(infile)
> {
> while(not infile.eof())
> {
> std::ostringstream data;
> data << infile.get();
> std::cout << data.str();
>
> }
>
> }
>

> else std::cout << "Failed to read it!\n";
>
> }
However i tested it with this secret message as data.txt
> ********************

The output was not the string that i typed in in plain english. Instead
I got:

> 424242424242424242424242424242424242424210-1
> Press ENTER to continue.
>

Then I tried it with different data.txt and got what looks like exactly
the same output:
> 4242424242424242424242424242424210-1
> Press ENTER to continue.
>
I typed in different words, but theres only 42 and 10-1????

I thought that std::cout << data.str(); should output the decoded words
i typed but presumably i need another function to do that. Does the
standard library have a function for this, or would i have to try and
write my own- Do you have any ideas what im missing on this?
thanks

ZikO

unread,
Feb 12, 2009, 11:12:50 AM2/12/09
to
picasso wrote:
> I typed in different words, but theres only 42 and 10-1????
>
> I thought that std::cout << data.str(); should output the decoded words
> i typed but presumably i need another function to do that. Does the
> standard library have a function for this, or would i have to try and
> write my own- Do you have any ideas what im missing on this?
> thanks
>
I simply copied your file, created my own data.txt with EOF at the end
such as:
ABCDEFGHIJKL\n

and this is what I got as output:
6566676869707172737475761310-1

which IMO looks like it works as it should. 1310 is i think the 2 bytes
end of line in DOS. -1 i suppose means stream reach the end of file.

PS. I use MinGW with GCC 4.3.0 in Windows XP

picasso

unread,
Feb 12, 2009, 12:20:44 PM2/12/09
to

Hi there,
Its NOT working as it should because I want the program to print out
the actual hidden text - in characters A-Z etc! What function do i
need to add to do this? If it works right, you should be able to
decipher the secret message I posted above, by running the program and
using it as data.txt.

I'm not up to speed with streams etc as yet so i'm not entirely sure
HOW to achieve the result im after.
But thanks for your help

Alf P. Steinbach

unread,
Feb 12, 2009, 1:06:59 PM2/12/09
to
* picasso:

If I understand this correctly you want your program to accept the input

********

read your mind about what those asterisks "hide", and then output whatever
you're thinking of, like

Mozilla!

Please note that the world's best computer scientists and mathematicans have
struggled with this problem since 1942, without success.

However, happily, the problem turned out to be mostly academic, because, first,
the Nazis, for some unimaginable reason, ditched the telepathic encryption
technique in favor of a Polish invention called the "Enigma" (it looked like a
bulky typewriter), and later on all kinds of mostly mechanical, non-ESP
techniques were employed by e.g. China, Russia and the US, not to mention banks
and other financial institutions. As far as I know only the old KGB and CIA
revived the old more advanced ESP-based encryption techniques, in the 1970's or
thereabouts, but they bungled it completely by insisting that the "volunteers"
use drugs such as LSD. And having no C++ programmers around to create proper
decryption programs the ********* messages were essentially indecipherable.

So, don't give up just because this program doesn't work. Just choose some more
tractable problem.

Cheers & hth.,

- Alf

picasso

unread,
Feb 12, 2009, 1:50:16 PM2/12/09
to
Alf P. Steinbach wrote:

> If I understand this correctly you want your program to accept the input
>
> ********
>
> read your mind about what those asterisks "hide", and then output
> whatever you're thinking of, like
>
> Mozilla!

Hi, no each '*' is representative of a ascii character & so if i
understand it right, each will have a unique int value. The '*' are just
tokens!
So in the secret message i posted above, I typed it in a dialog prompt
box for a program on my pc. That dialog automatically converted the text
into '****' etc. I then cut and paste this and put it in data.txt.

Now, the unique int values for each character MUST still reside in
data.txt. I have actually tested it by opening up the dialog for the
program and simply pasting the * stream into the dialog.

>
> Please note that the world's best computer scientists and mathematicans
> have struggled with this problem since 1942, without success.

> However, happily, the problem turned out to be mostly academic, because,
> first, the Nazis, for some unimaginable reason, ditched the telepathic
> encryption technique in favor of a Polish invention called the "Enigma"
> (it looked like a bulky typewriter), and later on all kinds of mostly
> mechanical, non-ESP techniques were employed by e.g. China, Russia and
> the US, not to mention banks and other financial institutions. As far as
> I know only the old KGB and CIA revived the old more advanced ESP-based
> encryption techniques, in the 1970's or thereabouts, but they bungled it
> completely by insisting that the "volunteers" use drugs such as LSD. And
> having no C++ programmers around to create proper decryption programs
> the ********* messages were essentially indecipherable.
>
> So, don't give up just because this program doesn't work. Just choose
> some more tractable problem.
> Cheers & hth.,
>
> - Alf

Thanks, but i dont believe that this problem is intractable. If my
program can convert each '*' to its unique ascii interger number, then
it will produce the output.

Alf P. Steinbach

unread,
Feb 12, 2009, 2:38:34 PM2/12/09
to
* picasso:

> Alf P. Steinbach wrote:
>
>> If I understand this correctly you want your program to accept the input
>>
>> ********
>>
>> read your mind about what those asterisks "hide", and then output
>> whatever you're thinking of, like
>>
>> Mozilla!
>
> Hi, no each '*' is representative of a ascii character & so if i
> understand it right, each will have a unique int value. The '*' are just
> tokens!
> So in the secret message i posted above, I typed it in a dialog prompt
> box for a program on my pc.

Huh, dialog prompt box?


> That dialog automatically converted the text
> into '****' etc. I then cut and paste this and put it in data.txt.
>
> Now, the unique int values for each character MUST still reside in
> data.txt.

Of course. This is, after all, the basic principle of homeopathics, and nobody
can deny that homeopathics works. Well, some silly persons do, but at least in
Norway most people just know that it works -- that it's actually the dilution
of the original drug in massive amounts of water that unmasks the *essence* of
the drug. And so it is of course with transformed text data. The essence of the
original text MUST still reside in the transformed text, since there is a causal
chain back to the original text (this article is unfortunately too short to
delve into the quantum-mechanicl explanation, but it revolves around so called
tangled states, which is used in advanced encryption: yet another connection!).


> I have actually tested it by opening up the dialog for the
> program and simply pasting the * stream into the dialog.

Of course.


>> Please note that the world's best computer scientists and mathematicans
>> have struggled with this problem since 1942, without success.
>
>> However, happily, the problem turned out to be mostly academic, because,
>> first, the Nazis, for some unimaginable reason, ditched the telepathic
>> encryption technique in favor of a Polish invention called the "Enigma"
>> (it looked like a bulky typewriter), and later on all kinds of mostly
>> mechanical, non-ESP techniques were employed by e.g. China, Russia and
>> the US, not to mention banks and other financial institutions. As far as
>> I know only the old KGB and CIA revived the old more advanced ESP-based
>> encryption techniques, in the 1970's or thereabouts, but they bungled it
>> completely by insisting that the "volunteers" use drugs such as LSD. And
>> having no C++ programmers around to create proper decryption programs
>> the ********* messages were essentially indecipherable.
>>
>> So, don't give up just because this program doesn't work. Just choose
>> some more tractable problem.
>> Cheers & hth.,
>>
>> - Alf
>
> Thanks, but i dont believe that this problem is intractable. If my
> program can convert each '*' to its unique ascii interger number, then
> it will produce the output.

Ah, possibly.

Well, good luck!


Cheers, & hth.,

- Alf

Bart van Ingen Schenau

unread,
Feb 12, 2009, 2:58:03 PM2/12/09
to
picasso wrote:

> Alf P. Steinbach wrote:
>
>> If I understand this correctly you want your program to accept the
>> input
>>
>> ********
>>
>> read your mind about what those asterisks "hide", and then output
>> whatever you're thinking of, like
>>
>> Mozilla!
>
> Hi, no each '*' is representative of a ascii character & so if i
> understand it right, each will have a unique int value. The '*' are
> just tokens!

Unfortunately, no.
The characters you typed can NOT be recovered from the sequence of *-s
that is shown on the screen.

> So in the secret message i posted above, I typed it in a dialog prompt
> box for a program on my pc. That dialog automatically converted the
> text into '****' etc. I then cut and paste this and put it in
> data.txt.

This is where your thinking takes the wrong turn. When using a
password-style input line (one that shows * instead of actual text),
The only correspondence between what you typed and what is shown in the
dialog box is the number of *-s shown.
The input field intercepts the characters you type before they can be
shown on the screen and diverts them to an internal buffer. The input
field then sends a '*' character to the screen.

What you copied to your data.txt file is really a bunch of '*'
characters.

>
> Now, the unique int values for each character MUST still reside in
> data.txt. I have actually tested it by opening up the dialog for the
> program and simply pasting the * stream into the dialog.

Did you only copy/paste the input and see that the same number of *-s
was shown both times, or did you actually verify that you entered valid
input both times?

>>
>> So, don't give up just because this program doesn't work. Just choose
>> some more tractable problem.
>> Cheers & hth.,
>>
>> - Alf
>
> Thanks, but i dont believe that this problem is intractable. If my
> program can convert each '*' to its unique ascii interger number, then
> it will produce the output.

Think about it. Every character you typed ends up looking like a '*'.
How many characters do you know that look visually identical to '*'?
You would need about 80 of them to encode all printing characters of
the basic ASCII character set in a reversible way.

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/

picasso

unread,
Feb 12, 2009, 3:42:56 PM2/12/09
to

Thanks - your explanation makes sense. I actually thought when i saw ***
it had a encoding of each letter. I did not realise that the actual
characters resided in another buffer and * was just exactly what it
appeared to be.

I just thought it would have been a fun project to implement such a program.

picasso

unread,
Feb 12, 2009, 6:06:18 PM2/12/09
to
To break new ground, it's important to have a "Can - Do" attitude. :)

Alf P. Steinbach

unread,
Feb 12, 2009, 7:04:57 PM2/12/09
to
* picasso:

> To break new ground, it's important to have a "Can - Do" attitude. :)

Yep.

Sorry, but I thought you were having us on.


Cheers,

- Alf

Bart van Ingen Schenau

unread,
Feb 13, 2009, 6:26:23 AM2/13/09
to
picasso wrote:

>
> I just thought it would have been a fun project to implement such a
> program.

In that case, I have a similar project for you that is actually doable.
Write a program that can decode this (ROT-13 encoded) text:
Jryy qbar, naq n tbbq qnl gb lbh.

picasso

unread,
Feb 13, 2009, 12:34:35 PM2/13/09
to
Bart van Ingen Schenau wrote:
> picasso wrote:
>
>> I just thought it would have been a fun project to implement such a
>> program.
>
> In that case, I have a similar project for you that is actually doable.
> Write a program that can decode this (ROT-13 encoded) text:
> Jryy qbar, naq n tbbq qnl gb lbh.
>
> Bart v Ingen Schenau
Thanks,
this will be a interesting program to work on. I'll post a solution to
it shortly. :)

picasso

unread,
Feb 17, 2009, 8:01:37 PM2/17/09
to
Bart van Ingen Schenau wrote:
> picasso wrote:
>
>> I just thought it would have been a fun project to implement such a
>> program.
>
> In that case, I have a similar project for you that is actually doable.
> Write a program that can decode this (ROT-13 encoded) text:
> Jryy qbar, naq n tbbq qnl gb lbh.
>
> Bart v Ingen Schenau

Gunaxf, V purngrq gb qrpbqr lbhe zrffntr ol hfvat fbzrbar ryfr'f cebtenz
- ohg v nz jbexvat ba qrirybcvat zl bja pbafbyr naq tabzr TGX THV
cebtenz gb qb guvf :)

--
Learning C++ http://myweb.tiscali.co.uk/thegallery

0 new messages