Jump to content
  • Advertisement
Sign in to follow this  

changed:problem with c++ strings +a question about wget

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

edit 2: tiny question about wget wich didn't deserve it's own thread is there a way to specify a filename? say i want to download something from http://hippyarecool.com/leetfile.mpg but i want it stored as thisisaseriousfile.mpg is there a way to do it on command line? (flought over the option list but didn't see it) any idear what could be going wrong there? MainIndexUrl="sometexthere"; MainIndexUrl+=FileCounter; MainIndexUrl+="&"; cout<<MainIndexUrl; assuming filecounter is 22if i remove the last line i have: (edit:filecounter is a STRING containing "22" not a int) sometexthere22 & with the last line i'd expect sometexthere22& but for some reason the & doesn't apear & seems to eat a char & i get that: sometexthere2 any idear? (i'm assuming & is a special char or soemthing?) ps:before someone rushes me for not using code tags i didn't do so because it would be harder to read (no types nor keyword in there so all you'd get is a big textbox with the same text inside beside it's a very tiny snippet) edit:this code throw an exception (last line replaced) MainIndexUrl="view.cgi?id=koh0130&now=3&jd=-1&ino="; MainIndexUrl+=FileCounter; MainIndexUrl+="test"; so seems it's not the & causing trouble? [Edited by - ranakor on December 1, 2004 4:16:48 PM]

Share this post

Link to post
Share on other sites
Usually "&" is a reference to an address in memory in C++.

my two guesses are to try an escape character "\&" (doubt it)
or use strcat to combine the two strings.

Share this post

Link to post
Share on other sites
i already tryed "\&" & it didn't work either( & i know & is a keyword but keyword aren't parsed usualy inside of "" (like you can do this i'm fairly sure)

mystring= "for continue break goto return"

so i assumed & had another meaning in "" like the \ does but i'm rather clueless there(

Share this post

Link to post
Share on other sites
sorry forgot to add filecounter is a string (& poses no problem) it's created that way

int counter=22
string filecounter=itoa(counter);

& removing the part with the & the mystring cout just fine (including counter at the end)

[Edited by - ranakor on December 1, 2004 1:48:17 PM]

Share this post

Link to post
Share on other sites
Original post by ranakor
string filecounter=atoi(counter);

I assume this is a typo? atoi is used to go from array to integer.

Share this post

Link to post
Share on other sites
'&' has a special meaning within win32 (it underlines the next character for shortcut keys). Since you're using 'cout' to print it to the console, that's not the case here.

Must be something with FileCounter then (itoa?).

Share this post

Link to post
Share on other sites
yup your right it's a typo (but only in the post) i'll just post the whole code (it doesn't fully make sence as it was going to be 2 prog & i'm actually coding the 2nd inside the 1st so just look for something messing up what i did not for other weirdo stuff p) oh year & i know all those globals are evil=)

Share this post

Link to post
Share on other sites
[SOURCE]#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
//globals for easyness's sake
string FilePath="c:\\test save avi\\";
string FileName="\\Dr Koh's Guitar Sarang VOD.htm";
string StrCurrentFileName;
string StrCurrentFileNameOut;
string MainIndexUrl;
string FileContent[100];
string WgetString;
string IndexFilePath="c:\\test save avi\\index\\index.htm";
string IndexFile;

char FileCounter[50]={0};
int counter=1;
char tmp;
struct indexing
int indexfile;
int indexurl;
int indexurlend;
int stringsize;

indexing currentindex;
indexing mainindex;
int main()
ifstream IndexParser(IndexFilePath.c_str());
MainIndexUrl+=FileCounter;//this doesnt crash
MainIndexUrl+="test";//this chrashes
ifstream CurrentFile(StrCurrentFileName.c_str());
ofstream CurrentFileOut(StrCurrentFileNameOut.c_str(),ios::app);
return 1;
return 0;

[Edited by - ranakor on December 2, 2004 7:17:26 PM]

Share this post

Link to post
Share on other sites
Why not use ostringstream (include <sstream>) to generate the strings? This way you do not have to handle conversion operations (itoa, which is platform specific code). So the operation becomes:

ostringstream ostr;
ostr << "view.cgi?id=koh0120&now=3&jd=-1&ino=" << counter << "&";
MainIndexUrl = ostr.str();

I tested this code on Linux and it worked find. Ampersand was in place with no missing characters.

A minor nitpick is that FileCounter is not initialized. Bad idea. Change it to be:

char FileCounter[50] = {0}; // Initialize the elements to zero

Hope this helps,

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!