Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 07-06-05   #1 (permalink)
PC Gamer
 
kris_cs1's Avatar
 
amd ati

Join Date: Apr 2005
Location: Chester, Cheshire
Posts: 218

Rep: 27 kris_cs1 is acknowledged by some
Unique Rep: 24
FAQs Submitted: 1
Trader Rating: 0
Default add two or more strings

Hey again, I can't find this out n the interent. i would expect it to be simple....
I want to add the below strings together to make one string.

Code:
"C:\\Documents and Settings\\Me\\Desktop\\Kris\\Word List\\";
Letter = 'a'
".txt";



Also while i'm here, how can i store the whole of a file in one string variable?

Told you i would be posting often :P
Feel free to take your time to answer... I'm in no hurry
Thanks
__________________
Kris



System: My System
CPU
AMD Sempron 2800+
Motherboard
ASUS A7N8X-VM
Sound Card
5.1 SURROUND SOUND
Power Supply
350W
Case
Black
OS
Windows XP Home SP2
Monitor
19"
kris_cs1 is offline   Reply With Quote
Old 07-06-05   #2 (permalink)
Lord of the Chicken Wings
 
VulcanDragon's Avatar
 
intel nvidia

Join Date: Aug 2004
Location: Columbus, OH
Posts: 4,991
Blog Entries: 25

FAQs Submitted: 1
Trader Rating: 0
Default

Are you talking C++ here? If so, you can use the strcat function.

http://www.cplusplus.com/ref/cstring/strcat.html

Some languages include a string concatenation operator. E.g. VB uses the ampersand, and Oracle SQL uses double vertical bars (||).
__________________
Vulcan Dragon
Core i7 920 @ stock 2.67
Currently Playing: Grand Theft Auto 4 (X360); Rock Band 2 (X360); Crysis (PC)
XBox Live Gamertag: Vulcan Draggon

System: Vulcan's New Hotness
CPU
Core i7 920
Motherboard
Asus P6T Deluxe
Memory
6GB Corsair XMS3 DDR3-1333
Graphics Card
EVGA GTX 260 (216)
Hard Drive
300GB Velociraptor (main)
Power Supply
ThermalTake 850W
Case
Lian Li PC-6077
CPU cooling
stock
OS
Vista x64 SP1
Monitor
Gateway FHD2400
VulcanDragon is offline Overclocked Account   Reply With Quote
Old 07-07-05   #3 (permalink)
PC Gamer
 
kris_cs1's Avatar
 
amd ati

Join Date: Apr 2005
Location: Chester, Cheshire
Posts: 218

Rep: 27 kris_cs1 is acknowledged by some
Unique Rep: 24
FAQs Submitted: 1
Trader Rating: 0
Default

Quote:
Originally Posted by VulcanDragon
Are you talking C++ here? If so, you can use the strcat function.

http://www.cplusplus.com/ref/cstring/strcat.html

Some languages include a string concatenation operator. E.g. VB uses the ampersand, and Oracle SQL uses double vertical bars (||).
yes, it is for C++.
The strcat() function works with the ".txt" but not in adding the single letter to the string as it is not a string itself . It says:

Quote:
cannot convert parameter 2 from 'char' to 'const char *'


Thanks
__________________
Kris



System: My System
CPU
AMD Sempron 2800+
Motherboard
ASUS A7N8X-VM
Sound Card
5.1 SURROUND SOUND
Power Supply
350W
Case
Black
OS
Windows XP Home SP2
Monitor
19"
kris_cs1 is offline   Reply With Quote
Old 07-07-05   #4 (permalink)
Programmer
 
MrSmiley's Avatar
 
amd nvidia

Join Date: Oct 2004
Location: Manhattan, Kansas
Posts: 1,060

Rep: 72 MrSmiley is acknowledged by some
Unique Rep: 57
FAQs Submitted: 1
Folding Team Rank: 747
Hardware Reviews: 1
Trader Rating: 0
Default

Quote:
Originally Posted by kris_cs1
Hey again, I can't find this out n the interent. i would expect it to be simple....
I want to add the below strings together to make one string.

Code:
  "C:\\Documents and Settings\\Me\\Desktop\\Kris\\Word List\\";
  Letter = 'a'
  ".txt";



Also while i'm here, how can i store the whole of a file in one string variable?

Told you i would be posting often :P
Feel free to take your time to answer... I'm in no hurry
Thanks
I actually do not remember if this works but give it a try, I know it works in VBScript, but casting doesn't , (Knowledge of VBScript is low) anyways take a look.

Code:
  #include<string>
 #include<iostream>
  
  int main()
  {
       string a="what\0", b="Do\0You\0Want?", total;
       total = a + b;
       cout << total;
       return 0;
  }
hehehe I'm actually hating that problem right now. http://www.overclock.net/showthread.php?t=32419
__________________
System: My System
CPU
Intel 2.8GHz
Motherboard
ESG smth
Power Supply
Antec TruePower 350Watt
OS
FreeBSD
MrSmiley is offline I fold for Overclock.net   Reply With Quote
Old 07-07-05   #5 (permalink)
Intel oc'er in training
 
intel ati

Join Date: Jun 2004
Location: Herts, UK
Posts: 2,569

Rep: 207 Zeus is acknowledged by manyZeus is acknowledged by manyZeus is acknowledged by many
Unique Rep: 142
Folding Team Rank: 1174
Trader Rating: 0
Default

I'm not a C+ expert but I think the code you need is...

char oPath = 'C:\\Documents and Settings\\Me\\Desktop\\Kris\\Word List\\';
char oLetter = 'a';
char oExt = '.txt';

char FullPath = oPath & oLetter & oExt;
__________________
E6600 L717A @ 3560Mhz CPUz validated --> ID 242627

X1950 scores: AM3: 126900 | 3DMark01: 45167 | 3DMark03: 20353 | 3DMark05: 11822 | 3DMark06: 5954


4870HD 1GB scores to come


System: Gaming Rig
CPU
E6600 L717A
Motherboard
Gigabyte GA-P35-DS3
Memory
A-Data DDR2 PC6400 (2x1GBMB)
Graphics Card
HD 4870 1024MB GDDR5
Hard Drive
Maxtor 250Gb 16Mb PATA
Sound Card
Onboard
Power Supply
Antec TPQ 850W modular
Case
PoS
CPU cooling
Zalman CNPS9500 LED
GPU cooling
Stock
OS
WinXP 32bit SP2
Monitor
Fujitsu CRT 19"
Zeus is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 07-07-05   #6 (permalink)
Lord of the Chicken Wings
 
VulcanDragon's Avatar
 
intel nvidia

Join Date: Aug 2004
Location: Columbus, OH
Posts: 4,991
Blog Entries: 25

FAQs Submitted: 1
Trader Rating: 0
Default

Quote:
Originally Posted by kris_cs1
yes, it is for C++.
The strcat() function works with the ".txt" but not in adding the single letter to the string as it is not a string itself .
Can't you send a pointer to variable a instead of variable a itself? I.e., &a?

Alternately, declare a pointer variable and assign it to point to a.
__________________
Vulcan Dragon
Core i7 920 @ stock 2.67
Currently Playing: Grand Theft Auto 4 (X360); Rock Band 2 (X360); Crysis (PC)
XBox Live Gamertag: Vulcan Draggon

System: Vulcan's New Hotness
CPU
Core i7 920
Motherboard
Asus P6T Deluxe
Memory
6GB Corsair XMS3 DDR3-1333
Graphics Card
EVGA GTX 260 (216)
Hard Drive
300GB Velociraptor (main)
Power Supply
ThermalTake 850W
Case
Lian Li PC-6077
CPU cooling
stock
OS
Vista x64 SP1
Monitor
Gateway FHD2400
VulcanDragon is offline Overclocked Account   Reply With Quote
Old 07-08-05   #7 (permalink)
Programmer
 
MrSmiley's Avatar
 
amd nvidia

Join Date: Oct 2004
Location: Manhattan, Kansas
Posts: 1,060

Rep: 72 MrSmiley is acknowledged by some
Unique Rep: 57
FAQs Submitted: 1
Folding Team Rank: 747
Hardware Reviews: 1
Trader Rating: 0
Default

Code:
 #include <cstdlib>
 #include <iostream>
 #include<string>
 
 using namespace std;
 
 int main(int argc, char *argv[])
 {
 	/*"C:\\Documents and Settings\\Me\\Desktop\\Kris\\Word List\\";
   Letter = 'a'
   ".txt";*/
 	string dir="C:\\Documents and Settings\\Me\\Desktop\\Kris\\Word List\\", fex=".txt", total;
 	total = dir + fex;
 	cout << total<<endl;
 	system("PAUSE");
 	return EXIT_SUCCESS;
 }
compiles out 0 errors 0 warnings, standard install of dev-c++.
__________________
System: My System
CPU
Intel 2.8GHz
Motherboard
ESG smth
Power Supply
Antec TruePower 350Watt
OS
FreeBSD
MrSmiley is offline I fold for Overclock.net   Reply With Quote
Old 07-08-05   #8 (permalink)
Lord of the Chicken Wings
 
VulcanDragon's Avatar
 
intel nvidia

Join Date: Aug 2004
Location: Columbus, OH
Posts: 4,991
Blog Entries: 25

FAQs Submitted: 1
Trader Rating: 0
Default

Quote:
Originally Posted by MrSmiley
#include<string>
Ah yes, a string library. Forgot about that. I never used it myself, I was more of a C programmer. I did everything the traditional (hard) way, with pointers and memory allocation statements.

But you forgot to include the single char "a" in your code sample. Does the string library handle single char variables the same as a string? I got to thinking about my solution after I posted it and realized that simlpy dereferencing the char variable probably won't work after all, because a char is not a null-terminated string as strcat requires. Does the string library convert char to null-terminated strings where required?
__________________
Vulcan Dragon
Core i7 920 @ stock 2.67
Currently Playing: Grand Theft Auto 4 (X360); Rock Band 2 (X360); Crysis (PC)
XBox Live Gamertag: Vulcan Draggon

System: Vulcan's New Hotness
CPU
Core i7 920
Motherboard
Asus P6T Deluxe
Memory
6GB Corsair XMS3 DDR3-1333
Graphics Card
EVGA GTX 260 (216)
Hard Drive
300GB Velociraptor (main)
Power Supply
ThermalTake 850W
Case
Lian Li PC-6077
CPU cooling
stock
OS
Vista x64 SP1
Monitor
Gateway FHD2400
VulcanDragon is offline Overclocked Account   Reply With Quote
Old 07-08-05   #9 (permalink)
Overclocker
 
Join Date: Dec 2004
Posts: 401

Rep: 65 Melraidin is acknowledged by some
Unique Rep: 48
FAQs Submitted: 4
Folding Team Rank: 217
Trader Rating: 1
Default

Quote:
Originally Posted by VulcanDragon
Ah yes, a string library. Forgot about that. I never used it myself, I was more of a C programmer. I did everything the traditional (hard) way, with pointers and memory allocation statements.

But you forgot to include the single char "a" in your code sample. Does the string library handle single char variables the same as a string? I got to thinking about my solution after I posted it and realized that simlpy dereferencing the char variable probably won't work after all, because a char is not a null-terminated string as strcat requires. Does the string library convert char to null-terminated strings where required?
The single character may be appended to the string with the + or += operator.
Melraidin is offline I fold for Overclock.net   Reply With Quote
Old 07-08-05   #10 (permalink)
PC Gamer
 
kris_cs1's Avatar
 
amd ati

Join Date: Apr 2005
Location: Chester, Cheshire
Posts: 218

Rep: 27 kris_cs1 is acknowledged by some
Unique Rep: 24
FAQs Submitted: 1
Trader Rating: 0
Default

Arrrggghhh! lol.
Thanks, that works except now because it is a string, it won't open.

Code:
infile.open(File1);
It says:

Quote:
'void std::basic_ifstream<_Elem,_Traits>:pen(const wchar_t *,std::ios_base:penmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *'


every time i can't do it
i'm so embarrased

__________________
Kris



System: My System
CPU
AMD Sempron 2800+
Motherboard
ASUS A7N8X-VM
Sound Card
5.1 SURROUND SOUND
Power Supply
350W
Case
Black
OS
Windows XP Home SP2
Monitor
19"
kris_cs1 is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 07:49 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.32132 seconds with 8 queries