Computing.Net > Forums > Unix > string declaration

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

string declaration

Reply to Message Icon

Name: Wond
Date: August 25, 2003 at 13:37:22 Pacific
OS: UNIX
CPU/Ram: Not Sure
Comment:

Hello Every one,

I have a problem related to string declaration in a small program I want to compile in UNIX. I have already included the and header files. For some reason the prgram is not recognizing declaration like "string filename". It is giving a message saying that string is used as a type but is not defined as a type. Below is shown part of the program, which also include other header files. I greatly appreciate your advise on the problem. Thanks.

Wond
// The Program does Simple Spectrum Subtraction
// August 15, 2003: Wond
//
#include
#include
#include // for atoi().
#include // For asprintf().
#include // for atan(), fabs() and pi.
#include // analyze many files as one.
#include // for getopt() and friends.
#include // C string utilities.
#include
#include
#include // For string streams.
#include
#include // We use the STL basic_string for filenames.
#include "TROOT.h"
#include "TFile.h"
#include "TH2.h"

string analysisfilename;
string outfilename; // String for output file(s).
string rootfilename; // Name of ROOT input file.
string histogramname("hist"); // Name of TH2F* to extract from ROOT file

float livetimefactor = 1.0;

int main(int argc, char **argv)
{
// String for input file.




Sponsored Link
Ads by Google

Response Number 1
Name: Wond
Date: August 25, 2003 at 13:44:49 Pacific
Reply:

This is a comment on my previous posting on string declaration. For some reason in my prvious posting, all the header file names with angle brackets are not shown. However all the string header files are included, string.h and the string, in the actual program. I appreciate your help.

Wond


0

Response Number 2
Name: Don Arnett
Date: August 25, 2003 at 20:15:21 Pacific
Reply:

What language?? C??

string is not a valid data type in C, unless you are using a special library.

Contrary to how it may sound, string.h does not define a string data type.

To use strings, you need to declare character arrays.

For example:

char analysisfilename[30];



0

Response Number 3
Name: Wond
Date: August 26, 2003 at 11:03:08 Pacific
Reply:

Thanks Don,

I was using C++. I tried "using namespace std", and it worked. What you suggested also works. Thanks for the suggestion.

Wond


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


unix commands Clone Sco Unix Drive



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: string declaration

concatenate strings www.computing.net/answers/unix/concatenate-strings/6153.html

Using variable string in AWK www.computing.net/answers/unix/using-variable-string-in-awk/5043.html

Extracting string using regular exp www.computing.net/answers/unix/extracting-string-using-regular-exp/5762.html