Thread: Copy to string

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Copy to string

    i need to copy Data.cFileName (it holds the file name) into the string that holds the rest of the path how would i do this
    Code:
    #include <windows.h>
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
    	HANDLE Find;
    	WIN32_FIND_DATA Data;
    	int decide;
    	string path = "c:\\Documents and Settings\\wmorrish\\Desktop\\Other\\";
    
    	Find = FindFirstFile("C:\\Documents and Settings\\wmorrish\\Desktop\\Other\\*.exe", &Data);

  2. #2
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    path += Data.cFileName;

    If I am understanding you correctly.

  3. #3
    Banned
    Join Date
    Oct 2004
    Posts
    250
    i cant seem to use strcmp to copy it into the string that holds the rest of the path

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    a) As you are using the 'string' class, you want <string> not <cstring>
    b) 'string' has + and += operators defined

    If you were using C-style strings, then you'd want strcat() from <cstring>

    You can check cppreference.com for additional info on these.

    *edit*
    Drat! Beaten.

    Anyway, strcmp compares strings. strcat concatenates strings. But they must be C-style strings. The string class is much nicer to use.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Banned
    Join Date
    Oct 2004
    Posts
    250
    thanks i got it working my C++ basics are not that solid i went straight to Direct x and OpenGL/WIN 32 maybe i should go back and learn them

  6. #6
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    this sounds like a virus
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by The Brain
    this sounds like a virus
    Upon seeing the title, and then author, I immediately became suspicious, trying to figure out what they were really up to...

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Replies: 3
    Last Post: 11-03-2002, 02:14 AM