Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

most likely you need to use stringstream class

#include <sstream>
...
...
istream& operator>> (istream& in,Format& b)
{

    //cout<<"enter's format";
    string word;
    string line;
    char just;
    size_t count=0;
    getline( in, line);
    stringstream str(line);
    while( str >> word )
    {
          b.add_word(word);
          count++;
    }

// Not sure about the following 
//

    cout<<"what justification would you like?"
        <<"pick from 'l','r','c'\n";
        in>>just;
                //cout<<"the value is"<<just<<"\n";
        //b.setJustification(just);
        in.unget();
    for(size_t i=0; i<count; i++)
    {
        b.add_justif(just);
    }
    
    
    
    //count=0;
    //cout<<"all the words are"<<b;
    return in;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could use

while(!dict.eof())//this will make it keep going untill the end of line
{
dict.getline(words,sizeof(dict));//this will read line by line 
}

hope it helps

Not really -- that loop will cause the last line to be inserted into the array twice.

>>,sizeof(dict)
You mean sizeof(word), assuming word is a character array instead of std::string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 14: where is max declared? Note that max is not the same as MAX.

You should use a <vector> instead of string array for two purposes: 1) avoid unnecessary memory allocation, 2) avoid possibility of array overflow (adding too many strings). The <vector> or <list> class will take care of both those problems for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That compiler can not compile 64-bit programs. Either buy the Pro edition or use g++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>will the value of counter automatically change as well?
No because they are two different variables. Line 10 only initializes the value of counter to be the same as number. From there on the value of counter does not change.

>>what is the best way to create a variable that will hold the original value of number
You don't have to do anything more because your program already does that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will have to write your own function. But its pretty simple

int main(int argc, char* argv[])
{
    std::string str = "Hello\\nWorld\\\\nAnother\\nWorld";
    size_t pos = 0;
    while( pos < str.size() && (pos = str.find("\\n", pos)) != string::npos)
    {
        if( str[pos-1] != '\\')
        {
            str.replace(pos,2,"\n");
        }
        else
        {
            // advance past "\\n"
            pos += 2;
        }
    
    }
    cout << str << "\n";
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I created a 1.2 gig text file that contained 10-character words (generated randomly). Then tried to read it into a std::list. The program crashed after reading just over 24 million words. Changed the program to use deque instead of list, and it read even fewer words before crashing. (my computer is running vista home, has 5 gig ram, and used vc++ 2008 express compiler/IDE)

Of course it would have been easier to check by calling the list's max_size() method. For deque

maxsize = 134217727
Press any key to continue . . .

Changed the program to use try/catch and got this:

23020000
23030000
Out of memory

// final size of the deque
size = 23031567

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I have 8 gigs of ram, so I know it's not running out of space

32-bit programs can not access all that memory at one time. Each 32-bit program is limited to about 2 gig ram.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Normally overload operators so that you can do mathematical or other operations with c++ classes. for example: cout << MyClass; assuming MyClass is an instance of some c++ class and you want that class to print the value of its class variables to the screen. Or you might want to add them MyClass++; There are lots of things you can do with overloaded operators, those are just two of them.

Which operators to overload depends on the c++ class and what you want it to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It seems that there is 10 3's in every 100;
There are 19 numbers between 1 and 100 that contain one or more 3s. 3 13 23 30 31 32 33 34 35 36 37 38 39 43 53 63 73 83 93 I thought about the mod operator too, but it won't work. Example: Enter max num = 100. 100 % 100 == 0, which is clearly wrong answer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>"(1) how to capture number of occurrences of 3 between 1 to 100? "

Write a for loop that counts from 1 to 100. Convert each int value to a string then test the string if it contains a '3'.

2) Do you know how to declare a function pointer? Almost like declaring a function prototype. For example, if you have a function that takes an int parameter and returns an int, then a function pointer might be int (*fn)(int);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Suggest you use getline() to read the entire line, then use stringstream object to split it into words.

std::string line;
ifstream in("file.txt");
while( getline( in, line) )
{
     std::string word;
    stringstream str(line);
    while( str >> word )
    {
       // now do something with this word
    }
    
}

As for the quotes -- you will have to parse the word and strip them out if they exist.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I see folks replying to threads with quotes that have the name of the original poster included - they have the form

nameOfPoster> quote

I've been crawling around the faq for the past hour or so, and haven't found any really newbie guides for using all the neat stuff that's available for doing that, for using code tags, etc. I'm sorry for this really dumb question - although I'm old in years, I'm very new to online forums and would like to be able to use this one sort of intelligently. Have I been looking in all the wrong places?

Thanks so much!

All you have to do is hit the "Reply W/Quote" button.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Get the input as a string then check each of the characters. If all is ok then convert that string to int (or other data type). Something along these lines.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int gallons;
    std::string input;
    cout << "Enter gallons\";
    cin >> input;
    bool ok  = true;
    for(int i = 0; i < input.length(); i++)
    {
       if( !isdigit(input[i]) )
       {
            cout << "Error\n";
            ok = false;
       }
   }
   if( ok == true )
   {
         stringstream str(input);
         str >> gallons;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Should I uninstall wxWidgets after buidling?

Not unless you never want to use it again. If your computer is running out of space then there are other files that should be removed before wxWidgets, such as all the compiler-generated files. If you are using Microsoft compiler then it will generate some pretty large precompiled header files (*.ncb).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't quite understand. By inlining the functions they don't get exported or references put in the *.a file??? Even when __declspec(dllexport) is used? Humm.

That's right because there's nothing in the DLL to export, unless objects of that class are created in the DLL, then they can of course be exported.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I was able to do it with Code::Blocks. This is nearly identical to the way I build them with Microsoft compilers. I started out by using the class exactly like you posted it (except for the extern "C" part). Then then it dawned on me that when all the methods are inlined like you have them you don't need that dll at all. So I split the implementation code into its own *.cpp file to force use of the DLL's *.a file

I put the CBox class in its own header file then used that same file in both the dll and application program.

// This is cbox.cpp, which is included in the DLL project.  That puts
// the code for the class into the *.a file which is linked with the
// application program.
#include "cbox.h"

CBox::CBox()
 {
     m_Length = m_Width = m_Height = 0;
 }

CBox::CBox(double dblLen, double dblWidth, double dblHeight)
 {
    std::cout << "Called CBox() Constructor\n";
    m_Length=dblLen;
    m_Width=dblWidth;
    m_Height=dblHeight;
 }

CBox::~CBox()
 {
    std::cout << "Called CBox() Destructor\n";
 }

 double CBox::Volume()
 {
    return m_Length*m_Width*m_Height;
 }
//
// This is the header file that is included in both the DLL and 
// application project.  Code::Blocks IDE defines DLL_EXPORT when
// a new DLL project is created, and I used that macro to determine
// whether the class is exported or imported.
//
#ifndef CBOX_H
#define CBOX_H

#ifndef DLL_EXPORT
#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif // BUILD_DLL
#endif // DLL_EXPORT

#include <iostream>


class …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why is that class declared extern "C" ? C programs can't call c++ classes, to that declaration is pointless.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Next time use code tags.

line 36: where is year declared?

line 46: why delete year immediately after entering its values?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

change_r() is pointless. All it does is return the same value that was passed in as the parameter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>anything wrong in the program?

1. its int main(). 2. Add return 0; as the last line in main()

3. Add '\n' to the end of Hello, making it "Hello\n"

4. You might need to add fflush(stdout) after that print statement.

If the above doesn't fix the problem then I don't know what's wrong.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is not a workable solution, but it shows how to typecast that last parameter. Compiled with vc++ 2008 Express.

#include <iostream>
#include <windows.h>
#include <vector>
#include <string>
using namespace std;

int main(int argc, char **argv)
{
    HWND hwnd = 0;
    vector<string> spnV;
    vector<string>::iterator it = spnV.begin();
    for(; it != spnV.end(); it++)
    {
        SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) (*it).c_str());
    }
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just typecast it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh! Sorry, my mistake. It should have been 'begin()'

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will have to post the code you changed. You obviously misspelled something because there is no such function as 'gegin'. Did you mean getline() ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I thought you said that LoadTextFileToEdit() function worked? Well, the function you posted can't work the way you think it does -- see my previous post about how to correct it.

And you might want to review this example program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean this loop?

for(int i = 0;i < nTimes; i++)
							{
								string* word = spnV[i];

What is the value of nTimes? Why are you using a string pointer? spnV is an array of strings, not pointers.

I think that should be like this: I like to use iterators because I have had a few problems with just using size(), especially if some of the strings have been deleted from the vector. Note: assume hwnd is a handle to the listbox control.

vector<string>::iterator it = spnV.gegin();
for(; it != spnV.end(); it++)
{
   SendMessage(hwnd, LB_ADDSTRING, 0, (*it).c_str());
}

}

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

They why are you wasting our time with that crap?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't make the function; I'm just supposed to use it.

Whoever made that function is out of their mind -- it doesn't work as written because it doesn't load the strings into the vector.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OMG what in the world are all those getline() calls???? If you want to put all those strings into the vector then use a loop! Use a string object to read the string and delete that damned character array (sztemp) which just takes up useless stack space. Replace lines 19 thru 75 with this simple loop.

string line;
while( getline(inStream, line) )
{
    spnV.push_back(line);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't matter. If the functions follow main() then you have to declare the function prototypes before they are called. In really small programs I like to put main() at the bottom so that I don't have to mess with creating the prototypes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what are the advantages and dis advatages between windows and console files?

A Windows project allows you to write GUI program (tutorial), such as one which you see when you run Notepad.exe. cout does not work with Windows programs, and requires WinMain() instead of main().

A console program has int main() and when run it normally opens up a console window. I think allegro programs require console programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>[Linker error] undefined reference to `WinMain@16'

You created the wrong kind of project -- create a new console project then copy/paste that program into it.

>>should I put that on line 25 of my code or right after mian ends?
Exactly as shown. Read the allegro tutorials here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You'll have to post the code as I'm sure there is another problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>These headers will "load" other headers..? Is this illegal?
Yes. Many standard system header files include other header files.

>>in this case its not bad, but if im using some audio processing function, it could name-clash with a similar function for midi.)
There will be no name clashes because that's exactly one of the purposes of namespaces. Everything in <iostream> is in std namespace.

>>Any Idea how i can call jack_create_client() in a similar way to Engine::Audio::jack_create_client() without this problem??

What problem? If jack_create_client() is in global namespace then just call ::jack_create_client() and that will be different then the function with the same name but in namespace Autio.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This works. But frankly I don't like using those win32 api file i/o functions because standard c++ std::fstream is a lot easier to work with.

#include <windows.h>
using namespace std;

int main()
{
    HANDLE hFile = CreateFile("TextFile1.txt", GENERIC_READ|GENERIC_WRITE,
            0,0,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

    if( hFile != INVALID_HANDLE_VALUE)
    {
        char text[] = "This line was added\r\n";
        DWORD dwBytesWritten = 0;
        SetFilePointer(hFile, 0, 0, FILE_END);
        WriteFile(hFile,text, strlen(text), &dwBytesWritten, 0);
        CloseHandle(hFile);

    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Write a comparison function that compared the substrings of each string.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctype.h>
using namespace std;

string getsubstr(const string& s)
{
    size_t pos = s.find('-');
    string v1 = s.substr(pos+1);
    // now remove any leading white space characters
    while( isspace(v1[0]) )
    {
        v1 = v1.substr(1);
    }
    return v1;
}
struct myclass {

    bool operator()(const string& s1, const string& s2)
    {
        string v1 = getsubstr(s1);
        string v2 = getsubstr(s2);
        return v1 < v2;
    }
} myobject;


int main()
{
    vector<string> towns;
    towns.push_back("Joshua Lynn Odom -  Bates Town");
    towns.push_back("Cindy Blue - Broken Arrow");
    towns.push_back("Donnie Kay - Oklahoma City");
    towns.push_back("Billy Bob - Durant");
    towns.push_back("Randall John - Lawton");
    towns.push_back("Danny Steven Ray - George Town");
    towns.push_back("Rodney White - Lone Grove");
    towns.push_back("Tammy Smiley - Ada");
    std::sort(towns.begin(), towns.end(), myobject);

    vector<string>::iterator it = towns.begin();

    for( ; it != towns.end(); it++)
        cout << *it << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here are a few tables that will show the ascii codes for all possible values. Note that decimal values 0 thru 32 are not printable so you won't see anything on your screen for them. Only values 33 thru 126 can be shown on the screen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Try this. GetNext() simply returns NULL and that is not what you want.

void Lobby::AddPlayer()
{
    //create a new player node
    cout << "Please enter the name of the new player: ";
    string name;
    cin >> name;
    Player* pNewPlayer = new Player(name);

    //if list is empty, make head of list this new player
    if (m_pHead == 0)
    {
        m_pHead = pNewPlayer;
        m_pTail = m_pHead; //m_pHead->GetNext();
    }
    //otherwise find the end of the list and add the player there
    else
    {
        m_pTail->SetNext(pNewPlayer);
         m_pTail = pNewPlayer;
         //m_pTail = m_pTail->GetNext();                   
                                        
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suggested that same thing a few months or a year ago but was boldly ignored. Dani is not amiable to creating new forums for whatever reason.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have never received that PM before either. And I ignored it because most of the questions do not apply to me and there were no appropriate answers for someone like me. I started to fill it out, but quit when I got to the part that asked for personal information.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first parameter needs to be a reference or pointer to a pointer. All that function is doing now is changing its own local copy of the pointer.

Suggest either of these changes: void double_array_1d(int** arr, int length) or this void double_array_1d(int*& arr, int length) If you use the first form you will have to make a couple minor other changes *arr = temp; and temp_arr[i] = (*arr)[i];

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what do I change to see a different name at the top?
Are you concerned with the version of the compiler (e.g. VC++ 2005 or VC++ 2008) or the version of the program?

-is duplicating folders the best method for making new versions?
IMO -- yes. The released version of those programs should be archived off somewhere, such as on disk or in a CVS type verson control program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've found that some compilers don't care whether you put in quotes or angle brackets. I personally like using the quotes to make it easier to distinguish compiler standard headers from others.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The new c++ standards, which will not be released for some time yet, is supposed to allow arrays to be allocated like that: int ay[size] where size is not a const integer. A few compilers may already support it, but if they do it is compiler-specifc.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A simple example

#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main()
{
std::vector< std::string > theList;
std::string str = "Hello World";
size_t pos = str.find(' ');
theList.push_back( str.substr(0, pos) );
theList.push_back(str.substr(pos+1));

// now display the two string
for(size_t i = 0; i < theList.size(); i++)
    cout << theList[i] << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Serkan: your whole problem is that you need to get yourself a nice woman to satisfy your lustful desires. One who can relate to you both body and mind, not someone just in virtual computerland. Get married, have a few kids. But stop that kickboxing, it ain't healthy for you :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> string s = "data.txt"; // an example
Delete that line

xiikryssiix commented: thank you for your repetitive help! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just put the strings in a vector: vector<string> ay; >>Oh and just for curiosity, in what manner does strtok modifies the string?
It replaces the separator token (such as a space or a comma) with '\0' then returns a pointer to the beginning of that segment of the character array. Therefore you can not pass it a string literal.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

std::string's find() method then use std::string's substr() method to extract the string. IMO its better than strtok() because it doesn't modify the original string.

If you were using c++/CLR then it's String class has a Split() method, but that isn't standard c++ and works only with Microsoft compilers.