Path Problem

hi guys,
i am a beginner in c++, so I faced my first problem relatively fast.

I want to access a .wav-file that is located in the sounds folder of the teamspeak-client.

I am able to get the appPath ("C:/Users/%user%/AppData/Local/TeamSpeak 3 Client") and I defined a second path ("sound/default/wave.wav").

How can I easily combine both paths that my result will be: "C:/Users/%user%/AppData/Local/TeamSpeak 3 Client/sound/default/wave.wav"?

thanks in advance!
Last edited on
You can use two strings and simply concatenate them together:

1
2
3
std::string one = "some";
std::string two = "thing";
std::string three = one + two; //"something" 
Last edited on
1
2
3
    std::string one = "C:/Users/%user%/AppData/Local/TeamSpeak 3 Client";
    std::string two = "sound/default/wave.wav";
    std::string result = one + '/' + two;


reference:
http://www.cplusplus.com/reference/string/string/operator+/
When using the provided code I am getting this error:
http://www11.pic-upload.de/18.07.14/vsttvx4v7xwg.png

After that I tried to #include <string>, but then I got tons of errors:
http://www11.pic-upload.de/18.07.14/gm91gh85yvxn.png
Last edited on
Could you show your actual code, rather than an image. (in both examples you gave the error was not within the portion of code displayed).
The first error is shown in the first picture:
1
2
3
std::string applicationPath(appPath);
std::string restOfPath = "sound/default/talkpower_requested.wav";
std::string soundPath = applicationPath + restOfPath;


the other error is triggered in the following line:
 
#include <string> 

and the results are the error shown in the second picture: (this is a defined/standard code, it's not written by me)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// cmath standard header
#pragma once
#ifndef _CMATH_
#define _CMATH_
#include <yvals.h>

#ifdef _STD_USING
 #undef _STD_USING
  #include <math.h>

  #include <xtgmath.h>

 #define _STD_USING

#else /* _STD_USING */
 #include <math.h>

 #include <xtgmath.h>
#endif /* _STD_USING */

 #if _GLOBAL_USING && !defined(RC_INVOKED)
_STD_BEGIN
using _CSTD abs; using _CSTD acos; using _CSTD asin;
using _CSTD atan; using _CSTD atan2; using _CSTD ceil;
using _CSTD cos; using _CSTD cosh; using _CSTD exp;
using _CSTD fabs; using _CSTD floor; using _CSTD fmod;
using _CSTD frexp; using _CSTD ldexp; using _CSTD log;
using _CSTD log10; using _CSTD modf; using _CSTD pow;
using _CSTD sin; using _CSTD sinh; using _CSTD sqrt;
using _CSTD tan; using _CSTD tanh;

using _CSTD acosf; using _CSTD asinf;
using _CSTD atanf; using _CSTD atan2f; using _CSTD ceilf;
using _CSTD cosf; using _CSTD coshf; using _CSTD expf;
using _CSTD fabsf; using _CSTD floorf; using _CSTD fmodf;
using _CSTD frexpf; using _CSTD ldexpf; using _CSTD logf;
using _CSTD log10f; using _CSTD modff; using _CSTD powf;
using _CSTD sinf; using _CSTD sinhf; using _CSTD sqrtf;
using _CSTD tanf; using _CSTD tanhf;

using _CSTD acosl; using _CSTD asinl;
using _CSTD atanl; using _CSTD atan2l; using _CSTD ceill;
using _CSTD cosl; using _CSTD coshl; using _CSTD expl;
using _CSTD fabsl; using _CSTD floorl; using _CSTD fmodl;
using _CSTD frexpl; using _CSTD ldexpl; using _CSTD logl;
using _CSTD log10l; using _CSTD modfl; using _CSTD powl;
using _CSTD sinl; using _CSTD sinhl; using _CSTD sqrtl;
using _CSTD tanl; using _CSTD tanhl;

using _CSTD float_t; using _CSTD double_t;

using _CSTD acosh; using _CSTD asinh; using _CSTD atanh;
using _CSTD cbrt; using _CSTD erf; using _CSTD erfc;
using _CSTD expm1; using _CSTD exp2;
using _CSTD hypot; using _CSTD ilogb; using _CSTD lgamma;
using _CSTD log1p; using _CSTD log2; using _CSTD logb;
using _CSTD llrint; using _CSTD lrint; using _CSTD nearbyint;
using _CSTD rint; using _CSTD llround; using _CSTD lround;
using _CSTD fdim; using _CSTD fma; using _CSTD fmax; using _CSTD fmin;
using _CSTD round; using _CSTD trunc;
using _CSTD remainder; using _CSTD remquo;
using _CSTD copysign; using _CSTD nan; using _CSTD nextafter;
using _CSTD scalbn; using _CSTD scalbln;
using _CSTD nexttoward; using _CSTD tgamma;

using _CSTD acoshf; using _CSTD asinhf; using _CSTD atanhf;
using _CSTD cbrtf; using _CSTD erff; using _CSTD erfcf;
using _CSTD expm1f; using _CSTD exp2f;
using _CSTD hypotf; using _CSTD ilogbf; using _CSTD lgammaf;
using _CSTD log1pf; using _CSTD log2f; using _CSTD logbf;
using _CSTD llrintf; using _CSTD lrintf; using _CSTD nearbyintf;
using _CSTD rintf; using _CSTD llroundf; using _CSTD lroundf;
using _CSTD fdimf; using _CSTD fmaf; using _CSTD fmaxf; using _CSTD fminf;
using _CSTD roundf; using _CSTD truncf;
using _CSTD remainderf; using _CSTD remquof;
using _CSTD copysignf; using _CSTD nanf;
using _CSTD nextafterf; using _CSTD scalbnf; using _CSTD scalblnf;
using _CSTD nexttowardf; using _CSTD tgammaf;

using _CSTD acoshl; using _CSTD asinhl; using _CSTD atanhl;
using _CSTD cbrtl; using _CSTD erfl; using _CSTD erfcl;
using _CSTD expm1l; using _CSTD exp2l;
using _CSTD hypotl; using _CSTD ilogbl; using _CSTD lgammal;
using _CSTD log1pl; using _CSTD log2l; using _CSTD logbl;
using _CSTD llrintl; using _CSTD lrintl; using _CSTD nearbyintl;
using _CSTD rintl; using _CSTD llroundl; using _CSTD lroundl;
using _CSTD fdiml; using _CSTD fmal; using _CSTD fmaxl; using _CSTD fminl;
using _CSTD roundl; using _CSTD truncl;
using _CSTD remainderl; using _CSTD remquol;
using _CSTD copysignl; using _CSTD nanl;
using _CSTD nextafterl; using _CSTD scalbnl; using _CSTD scalblnl;
using _CSTD nexttowardl; using _CSTD tgammal;

using _CSTD fpclassify; using _CSTD signbit;
using _CSTD isfinite; using _CSTD isinf;
using _CSTD isnan; using _CSTD isnormal;
using _CSTD isgreater; using _CSTD isgreaterequal;
using _CSTD isless; using _CSTD islessequal;
using _CSTD islessgreater; using _CSTD isunordered;
_STD_END
 #endif /* _GLOBAL_USING */

#endif /* _CMATH_ */

/*
 * Copyright (c) 1992-2013 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.40:0009 */
Last edited on
I am writing a teamspeak plugin, so I edited the original:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifdef _WIN32
#pragma warning (disable : 4100)
#include <Windows.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
#include "shlobj.h"
#include "public_errors.h"
#include "public_errors_rare.h"
#include "public_definitions.h"
#include "public_rare_definitions.h"
#include "ts3_functions.h"
#include "plugin.h"

static struct TS3Functions ts3Functions;

#ifdef _WIN32
#define _strcpy(dest, destSize, src) strcpy_s(dest, destSize, src)
#define snprintf sprintf_s
#else
#define _strcpy(dest, destSize, src) { strncpy(dest, src, destSize-1); (dest)[destSize-1] = '\0'; }
#endif

#define PLUGIN_API_VERSION 20

#define PATH_BUFSIZE 512
#define COMMAND_BUFSIZE 128
#define INFODATA_BUFSIZE 128
#define SERVERINFO_BUFSIZE 256
#define CHANNELINFO_BUFSIZE 512
#define RETURNCODE_BUFSIZE 128

static char* pluginID = NULL;

#ifdef _WIN32
static int wcharToUtf8(const wchar_t* str, char** result) {
	int outlen = WideCharToMultiByte(CP_UTF8, 0, str, -1, 0, 0, 0, 0);
	*result = (char*)malloc(outlen);
	if (WideCharToMultiByte(CP_UTF8, 0, str, -1, *result, outlen, 0, 0) == 0) {
		*result = NULL;
		return -1;
	}
	return 0;
}
#endif

/*********************************** Required functions ************************************/
const char* ts3plugin_name() {
#ifdef _WIN32
	static char* result = NULL;
	if (!result) {
		const wchar_t* name = L"Support Notification";
		if (wcharToUtf8(name, &result) == -1) {
			result = "Support Notification";
		}
	}
	return result;
#else
	return "Support Notification";
#endif
}

const char* ts3plugin_version() {
	return "1.0";
}

int ts3plugin_apiVersion() {
	return PLUGIN_API_VERSION;
}

const char* ts3plugin_author() {
	return "Dione";
}

const char* ts3plugin_description() {
	return "This plugin will play a notification sound, if a user joins a support channel.";
}

void ts3plugin_setFunctionPointers(const struct TS3Functions funcs) {
	ts3Functions = funcs;
}

int ts3plugin_init() {
	char appPath[PATH_BUFSIZE];
	char resourcesPath[PATH_BUFSIZE];
	char configPath[PATH_BUFSIZE];
	char pluginPath[PATH_BUFSIZE];

	printf("PLUGIN: init\n");

	ts3Functions.getAppPath(appPath, PATH_BUFSIZE);
	ts3Functions.getResourcesPath(resourcesPath, PATH_BUFSIZE);
	ts3Functions.getConfigPath(configPath, PATH_BUFSIZE);
	ts3Functions.getPluginPath(pluginPath, PATH_BUFSIZE);

	printf("PLUGIN: App path: %s\nResources path: %s\nConfig path: %s\nPlugin path: %s\n", appPath, resourcesPath, configPath, pluginPath);

	return 0;
}

void ts3plugin_shutdown() {
	printf("PLUGIN: shutdown\n");
	if (pluginID) {
		free(pluginID);
		pluginID = NULL;
	}
}

/************************** TeamSpeak callbacks ***************************/

void ts3plugin_onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage) {
	char appPath[PATH_BUFSIZE];
	ts3Functions.getAppPath(appPath, PATH_BUFSIZE);

	std::string applicationPath(appPath);
	std::string restOfPath = "sound/default/talkpower_requested.wav";
	std::string soundPath = applicationPath + restOfPath;

	if (newChannelID == 33948)
	{
		ts3Functions.playWaveFile(1, soundPath);
	//	ts3Functions.requestSendChannelTextMsg(serverConnectionHandlerID, appPath, 17148, NULL);
	}
	if (newChannelID == 33949)
	{
		ts3Functions.playWaveFile(1, soundPath);
		//	ts3Functions.requestSendChannelTextMsg(serverConnectionHandlerID, appPath, 17148, NULL);
	}
}
Thanks for the effort you made to post the code. What I meant previously was, when the compiler issues a message about errors in a standard header file, only on extremely rare occasions is that the actual problem, it is merely a symptom and the error is elsewhere, in a different file.

Because of the number of additional headers required, I've not been able to compile the code. However, it looks like you are using C rather than C++ and so rather than introducing std::string, it is probably simpler to continue to use c-strings, and in particular the strcat function.

Example, this could go in the function ts3plugin_onClientMoveEvent() instead of using std::string:
1
2
3
    char restOfPath[] = "sound/default/talkpower_requested.wav";
    strcat(appPath, "/");
    strcat(appPath, restOfPath);


after that point, the appPath should contain its original contents plus the required additional text. (I see no particular reason for the intermediate '/' to be kept separate, presumably it could be inserted at the start of restOfPath, which simplifies things slightly).

reference:
http://www.cplusplus.com/reference/cstring/strcat/

I Hope this helps.
I applied your suggestion to my code and ..... it perfectly works now :D
I was a little bit confused as on this screen: http://www11.pic-upload.de/18.07.14/vsttvx4v7xwg.png , it says c++ (right side --> properties).

thanks a thousand times ;)
Topic archived. No new replies allowed.