LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 06-19-2004, 02:14 AM   #1
lrt2003
Member
 
Registered: Mar 2004
Distribution: Fedora 10
Posts: 182

Rep: Reputation: 30
C++: char* to string, converting? rewriting program? need substr!


Hi there!

I'm writing an app in C++.. I need a function similar to SUBSTR in the string class. however, I'm doing it the char way (no good reason why, though)

I want to print "messy" from an index value of 6 (or so). But I can't seem to do find a function to do this in the classic string.h

How would I convert this to string class? or, is there a method of doing what I want in string.h?

Thanks for any help.

Relevant code is below.

char buffer[1000];
char buffer1[1000];
char titlestr;
char * messy;
if (! messagefile2.is_open())
{ cout << "Error opening file"; exit (1); }

while (! messagefile2.eof())
{
messagefile2.getline(buffer,1000);
strcat (buffer, "\n");
strcat (buffer1, buffer);
}
cout << buffer1;
// memcpy (titlestr,buffer,strlen(buffer)+1);
messy = strstr (buffer1, "Title:");
messy = strtok (messy, "\n");
cout << messy << "\n";
 
Old 06-19-2004, 02:37 AM   #2
lrt2003
Member
 
Registered: Mar 2004
Distribution: Fedora 10
Posts: 182

Original Poster
Rep: Reputation: 30
messy = messy+7;

omg!

thanks lrt2003
 
Old 06-19-2004, 03:20 AM   #3
bahramH
Member
 
Registered: Apr 2004
Location: France
Distribution: Mandrake
Posts: 67

Rep: Reputation: 15
I would also suggest considering the good old C function "sprintf" which is getting out of fashion nowadays but which is extremely powerfull.
 
  


Reply



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
c++ : replacing a char in a string cb951303 Programming 20 02-25-2015 08:18 PM
python: converting a 3 character octal string into and ASCII char llama_meme Programming 1 07-06-2010 02:00 PM
How to convert string to char? twirl Programming 27 10-13-2005 07:11 AM
C++ -> Converting strings to char* Dark Carnival Programming 1 01-25-2005 04:17 PM
Converting int value to char liguorir Programming 8 05-23-2004 07:21 PM

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

All times are GMT -5. The time now is 10:38 PM.

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