append characters to string

Hi
I want to create a for loop, that would compare two sets numbers in each iteration and return either 1 if the first number is bigger then the second or 0 if it's the opposite. This I have already done. Then I want to store these numbers in one string so the final string would look like this 01101101010011. I am unable to find a way to create such code that would append one number each iteration to the string.
Thanks in advance
You could just use .push_back() like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string global_string;

int checker(int first, int second) {
     global_string.push_back(first); //push_back() inserts something into the end of a vector (strings are a vector of chr)
     global_string.push_back(second);
     if(first > second) {
          global_string.push_back(1);
          return 1;
     } else if (second > first) {
          global_string.push_back(0);
          return 0;
     } else {
          return -1; //strings match...don't know what you want to do there...
     }
}


You would have to incorporate this into your loop, since I do not know what you are iterating through.
Last edited on
Thanks for help, but it doesn't work and I have no idea why...
The compiler says

error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

I have all these includes in my code and I think <string> should cover this, so I don't know why it isn't working.
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
#include <math.h>

I have Microsoft Visual C++ 6
Last edited on
>> I have Microsoft Visual C++ 6

There's your problem. Someone will soon tell you where you can download Express Edition 2008
Yeah I figured that out when I was browsing other string functions and they didn't work either. I'm downloading VS 2008 pro trial from MS site, hope it will work there.
Ok I've managed to make it work in 2008 pro, I'm having trouble with build though. I've imported the workspace, fixed some warnings but I keep getting

Project : error PRJ0003 : Error spawning 'mt.exe'.

error all the time while build is in process. The exe of my program is created, so I can use it, but still this should be fixed somehow I guess. I think it is connected with the manifest, but I have no idea what it is used for.
closed account (z05DSL3A)
If you create a new project (just a simple on) and build that; does it also have error PRJ0003?


Yeah, it won't work even with simple code like this one.

1
2
3
4
5
6
7
8
9
10
// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}


Always the same error.
Last edited on
Visual Studio 2008 doesn't seem to have stdafx.h. In fact, I can't even use _tmain(). I can change _TCHAR* to TCHAR* and #include <windows.h>, but that still leaves an error where _tmain() is undefined according to the linker.

To get around this, you need to #include <tchar.h> instead. That should fix that last program.
Last edited on
closed account (z05DSL3A)
@Kvakac
I have seen this sort of problem in the past (I think is was with VS2005), I'm trying to remember how it was resolved, what is coming to mind at the moment is the old faithful re-install or posibaly checking the path variables of windows and VS.

@rpgfan3233
stdafx.h is created by the prject wizard, it has the windows.h... includes in it.
Have you tried disabling pre-compiled headers and removing (don't delete them yet) stdafx.h and stdafx.cpp from the solution?

Project => [Solution name] Properties => Configuration Properties => C/C++ => Precompiled Headers => Create/Use Precompiled Header: Not Using Precompiled Headers

If I do that, then Visual C++ 2008 Express Edition compiles and links everything just fine.
Last edited on
closed account (z05DSL3A)
@rpgfan3233
The error that Kvakac is having "error PRJ0003 : Error spawning 'mt.exe'" is nothing to do with the precompiled header. The reason I asked if there was a problem with a new project was to see if the conversion of a VC6 project was at fault.
Yes that is the case, it produces this error regardless of the code. It must have something to do with the manifest. Could it be that I have only trial version of MSVS 2008 ?
Anyway the program is created normally so it only bothers me a bit.
closed account (z05DSL3A)
The buildlog may give more detail on why spawning mt.exe fails. Buildlog.htm should be in the debug or release directory of you project.
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
Build Log
 	 	

Build started: Project: GlovCont, Configuration: Debug|Win32

Command Lines
 	 	

Creating temporary file "c:\!diplom\Debug\RSP00000C30083756.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fp".\Debug/GlovCont.pch" /Fo".\Debug/" /Fd".\Debug/" /W3 /c /ZI /TP ".\GlovCont.cpp"
]
Creating command line "cl.exe @"c:\!diplom\Debug\RSP00000C30083756.rsp" /nologo /errorReport:prompt"
Creating temporary file "c:\!diplom\Debug\RSP00000D30083756.rsp" with contents
[
/OUT:".\Debug/GlovCont.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:".\Debug\GlovCont.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Debug/GlovCont.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE:NO /MACHINE:X86 odbc32.lib odbccp32.lib fgloved.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

".\Debug\GlovCont.obj"
]
Creating command line "link.exe @"c:\!diplom\Debug\RSP00000D30083756.rsp" /NOLOGO /ERRORREPORT:PROMPT"
Creating temporary file "c:\!diplom\Debug\RSP00000E30083756.rsp" with contents
[
/out:".\Debug\GlovCont.exe.manifest" /manifest

".\Debug\GlovCont.exe.intermediate.manifest"
]
Creating command line "mt.exe @"c:\!diplom\Debug\RSP00000E30083756.rsp" /nologo"

Output Window
 	 	

Compiling...
GlovCont.cpp
Linking...
Creating manifest...
Project : error PRJ0003 : Error spawning 'mt.exe'.

Results
 	 	

Build log was saved at "file://c:\!diplom\Debug\BuildLog.htm"
GlovCont - 1 error(s), 0 warning(s)
closed account (z05DSL3A)
Posible problems.

Insufficient security privileges. Verify that you have sufficient security privileges.

The executable paths specified in VC++ Directories do not include the path for the tool that you are attempting to run.

Maybe MT.exe is corupt, try running it from the comand line.

I've uninstalled the 2008 pro trial and downloaded 2008 express edition to check if it isn't something in my system and it works fine there , no problems with embedding manifests or anything else. Maybe the installation files were corrupt, I don't know. I guess this express edition will be sufficient for my needs.
Anyway, thanks for help everyone
Topic archived. No new replies allowed.