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 02-14-2007, 04:26 AM   #1
deVas
LQ Newbie
 
Registered: Jun 2004
Posts: 14

Rep: Reputation: 0
Question stringstream problem


Hi,
I think I have not really understood how stringstreams work in c++. I have this code:
Code:
const char* CAPFILEPREFIX = "cap";
const char* CAPFILESUFFIX = "lst";

int main(int argc,char** argv)
{
[definitions skipped]
	stringstream name(stringstream::in|stringstream::out);			// formatter

	// determine number of cams to capture
	if(argc < 2)
		cout << "Usage: calibRecord <numberOfCams>" << endl;
	else
		name << argv[1];
	name >> camcount;

[code skipped]	

		name.str(string(""));
//		name.sync();
		name << string(CAPFILEPREFIX) << i; 
	
		name << "." << string(CAPFILESUFFIX);
		cout << name.str().c_str() << endl; [debug]
		outs.push_back(new ofstream(name.str().c_str(),ios::trunc));

[code skipped]	
}
Unfortunately the debug output is just an emtpy line. It seems name is initialised with the emtpy string, but filling with '<<' operator again does not work.
What is wrong?
bye,
devas
 
Old 02-14-2007, 09:05 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
i dont see anything that stands out in that code, so it may be a problem somewhere else.

it could be that an error flag is getting set on the stringstream somewhere causing it to fail on future operations. without all the code its hard to say.
 
  


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
stringstream as class member variable xhi Programming 15 10-13-2006 11:52 AM
c++ stringstream greg108 Programming 7 06-24-2005 07:48 AM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

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

All times are GMT -5. The time now is 07:08 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