|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
add two or more strings
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||
|
PC Gamer
|
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
|
||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||
|
Lord of the Chicken Wings
![]() |
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
|
|||||||||||
|
|
|
|
#3 (permalink) | ||||||||||
|
PC Gamer
|
Quote:
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:
Thanks
__________________
Kris
|
||||||||||
|
|
|
|
|
#4 (permalink) | ||||||
|
Programmer
|
Quote:
, (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;
}
|
||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
Intel oc'er in training
|
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;
|
|||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||
|
Lord of the Chicken Wings
![]() |
Quote:
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
|
||||||||||||
|
|
|
|
#7 (permalink) | |||||
|
Programmer
|
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;
}
|
|||||
|
|
|
|
#8 (permalink) | ||||||||||||
|
Lord of the Chicken Wings
![]() |
Quote:
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
|
||||||||||||
|
|
|
|
#9 (permalink) | |
|
Overclocker
|
Quote:
__________________
DD TDX waterblock DD Maze 4-1 CPU (w. Peltier) Swiftech pump DD reservoir DD radiator Dual heatercore |
|
|
|
|
|
#10 (permalink) | |||||||||
|
PC Gamer
|
Arrrggghhh! lol.
Thanks, that works except now because it is a string, it won't open. Code:
infile.open(File1); Quote:
every time i can't do it i'm so embarrased
__________________
Kris
|
|||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|