LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-04-2004, 11:28 AM   #1
ToothlessRebel
Member
 
Registered: Jun 2004
Location: FL, USA
Distribution: Slackware 9.1
Posts: 190

Rep: Reputation: 30
Storing Strings


I am admittedly a newbie, but working on amending that. My newest learning experience is something that has frustrated me in the past, but now I find something fantastic and .... can't make it work!

Trying to use the type
Code:
string
by using
Code:
#include <string>
by using the following code (straight from my class textbook, Alternate Version of Starting Out With C++ 4th Edition) with gcc v3.2.3:

Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string movieTitle;
movieTitle = "Wheels of Fury";
cout << "I like " << movieTitle << endl;
return 0;
}
When I try and compile I get:

C++/test.cpp:10:2: warning: no newline at end of file

It compiles, and creates the executable, which when ran displays nothing. Why is it not displaying the output as I would expect:

Quote:
I like Wheels of Fury

Last edited by ToothlessRebel; 09-04-2004 at 11:29 AM.
 
Old 09-04-2004, 11:58 AM   #2
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
Hi,
I cannot reproduce your problem, your code works for me as expected - I have g++ 3.3.1 though.

Does your program work without using std::string? How do you compile your program?

So long...
bruce
 
Old 09-04-2004, 12:08 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The warning is because your last line is probably } instead of a blank line. No big deal.

The reason it probably isn't displaying anything is because you are probably running the Linux test program. try typing

which test

And you will probably get the result:

/usr/bin/test

To run your own test program, try executing it like so:

./test
 
Old 09-04-2004, 11:03 PM   #4
ToothlessRebel
Member
 
Registered: Jun 2004
Location: FL, USA
Distribution: Slackware 9.1
Posts: 190

Original Poster
Rep: Reputation: 30
To answer bruce ford, no.

Code:
#include <iostream>
#include <string>

int main()
{
 string monster;
 monster = "Zombie";
 cout << "The monster is a " << monster << endl;
}
Produces:

Quote:
C++/monster.cpp: In function `int main()':
C++/monster.cpp:6: `string' undeclared (first use this function)
C++/monster.cpp:6: (Each undeclared identifier is reported only once for each
function it appears in.)
C++/monster.cpp:6: syntax error before `;' token
C++/monster.cpp:7: `monster' undeclared (first use this function)
C++/monster.cpp:8: `cout' undeclared (first use this function)
C++/monster.cpp:8: `endl' undeclared (first use this function)
I can thank deiussum though, I think he may be right. Recompiling the above code with the "using namespace std;" in place, and compiling with "g++ C++/monster.cpp -o C++/monster" the code ran fine.

Thanks a million, I had no idea what the Linux "test" program was.
 
Old 09-05-2004, 03:16 AM   #5
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
hi rebel,

great that things are solved.
No I didn't mean to take out the 'using namespace std;' line but to use char* instead of string.

Have fun,
bruce
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
Password storing program? Ariod Linux - Software 2 09-09-2005 06:25 PM
Trying to use a vector for storing pointers... (C++) Dark Carnival Programming 7 08-09-2005 05:40 PM
Tk: Storing Output of Program Kenji Miyamoto Programming 4 06-25-2005 01:57 AM
Storing xvidtune settings? r_jensen11 Slackware 2 02-17-2004 07:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration