Thomas Matthews wrote:[color=blue]
>
hoggmeister@gmail.com wrote:
>
>[color=green]
>>Hi,
>>
>>Im new to C coming from a java background. I having difficulty
>>adjusting to C and was hoping someone could help me with a little
>>simple code to get started. I would like a little program that outputs
>>on to the console a message like "please enter some text" then when the
>>user enters text it gets stored in a char array or whatever is best. I
>>then want to check that the array is no longer than 25 chars ( i dont
>>know if malloc is required or not ) and if it is less than 25 it gets
>>stored in virtual memory if not then it loops and asks for input again.
>> Just a nice easy one so i can put in debugger to understand how the
>>code works. Thanks for looking.
>>[/color]
>
>
> #include <iostream>
> #include <string>
> #include <vector>
> using namespace std;
>
> int main(void)
> {
> string data;
> static vector<string> virtual_memory;
> while (true)
> {
> cout << "please enter some text";
> getline(cin, data);
> if (data.length() >= 25)
> {
> virtual_memory.push_back(data);
> }
> } // End: while true
> return 0;
> }[/color]
I'm having trouble getting this code to work; can
you tell me what's wrong? Here's what the compiler says:
bogus.c:1:20: iostream: No such file or directory (ENOENT)
bogus.c:2:18: string: No such file or directory (ENOENT)
bogus.c:3:18: vector: No such file or directory (ENOENT)
bogus.c:4: parse error before "namespace"
bogus.c:4: warning: type defaults to `int' in declaration of `std'
bogus.c:4: ISO C forbids data definition with no type or storage class
bogus.c: In function `main':
bogus.c:8: `string' undeclared (first use in this function)
bogus.c:8: (Each undeclared identifier is reported only once
bogus.c:8: for each function it appears in.)
bogus.c:8: parse error before "data"
bogus.c:9: warning: ISO C forbids nested functions
bogus.c:9: syntax error before '<' token
bogus.c:10: `true' undeclared (first use in this function)
bogus.c:12: `cout' undeclared (first use in this function)
bogus.c:13: warning: implicit declaration of function `getline'
bogus.c:13: `cin' undeclared (first use in this function)
bogus.c:13: `data' undeclared (first use in this function)
bogus.c:16: `virtual_memory' undeclared (first use in this function)
bogus.c:18: parse error before '/' token
bogus.c:12: warning: statement with no effect
bogus.c:20: warning: control reaches end of non-void function
(An oddity: The lines of diagnostic messages outnumber
the lines of source code.)
--
Eric.Sosman@sun.com